08-01-2006, 22:43
|
|
|
חבר מתאריך: 24.11.05
הודעות: 317
|
|
בניתי תוכנית בC של מכונת משקאות מרוב שעמום- כנסו תגידו מה דעתכם
הייי...
היה לי משעמם אז בניתי תוכנית של מכונת משקעות.
אני אתן קצת הסבר על התוכנית ואז הציג אותה, בבקשה תתיחסו אליה ותנו עצות לשיפור.
קודם כל- התוכנית הולכת ככה: קליטת מחיר המשקה המבוקש-->קליטת הכסף שהוכנס למכונה-->בדיקה אם חסר כסף (אם חסר, להוסיף), ואם הוכנס יותר מידי כמה עודף צריך לקבל.
קליטת מחיר המשקה מתבצעת על פי קודים (את הקודים ניתן לראות ברגע הרצת התוכנית), ישנה מסננת נודניקית שעד שלא הכנסת קוד נכון היא לא תתן להמשיך.
התוכנית (זה קצת ארוך זה בהצלחה) :
קוד PHP:
#include <stdio.h> #include <conio.h> int itemP_mesanenet () { int codeP; printf("Enter now-->"); scanf("%d",&codeP); while (!(codeP>0 && codeP<8)) { printf("Wrong chose, try again-->"); scanf("%d",&codeP); } return (codeP); } float get_itemP() { int codeP; float price; printf("Enter number of the item that you want to buy from the list:\n"); printf("\tEnter 1 for instant coffee\t price: 2.25 NIS\n"); printf("\tEnter 2 for black coffee\t price: 2.25 NIS\n"); printf("\tEnter 3 for tea\t\t\t price: 1.30 NIS\n"); printf("\tEnter 4 for chocolate\t\t price: 2.50 NIS\n"); printf("\tEnter 5 for soup\t\t price: 3.10 NIS\n"); printf("\tEnter 6 for coke\t\t price: 3.30 NIS\n"); printf("\tEnter 7 for orange juice\t price: 3.20 NIS\n"); codeP=itemP_mesanenet(); switch (codeP) { case 1: case 2: price=2.25; break; case 3: price=1.30; break; case 4: price=2.50; break; case 5: price=3.10; break; case 6: price=3.30; break; case 7: price=3.20; break; } return (price); } float get_pay() { float pay; printf("Enter coin-->"); scanf("%f",&pay); return (pay); } void check(float itemP,float pay) { float HowMore,more,change; while (itemP>pay) { HowMore=itemP-pay; printf("You need to enter more money, you need to enter more %0.2f\n",HowMore); printf("Please enter more money-->"); scanf("%f",&more); pay=pay+more; } if (itemP==pay) printf("Thank you for using the drink machine!"); else { change=pay-itemP; printf("You need to get %0.2f change",change); } } int main() { float itemP,pay; itemP=get_itemP(); pay=get_pay(); check(itemP,pay); getch(); }
|