20-12-2008, 08:55
|
|
|
|
חבר מתאריך: 10.10.06
הודעות: 64
|
|
חבר'ה תודה רבה על הסבלנות, במיוחד לך Dragonion
ישבתי על זה יחד עם העצות שלכם וכמעט כל הקוד רשום.
הייתי רוצה שאולי תעיפו עליו מבט במיוחד על נקודות ספציפיות ותגידו לי אם זה תקין ויפעל לדעתכם כמו שצריך (אני יודע שזה לא הקוד האופטימלי אבל כרגע חשוב לי רק שזה יעבוד), ויש נקודה בסוף שאני לא מצליח לפתור ואני מקווה שהיא לא תגרום לי לשנות את כל הקוד.. אתם כבר תראו.
קוד PHP:
#include <stdio.h> int main (void) { double People_including_kids=0; char is_a_vip; double kids_invovled=0; int people_not_including_kids=0; int PriceForDay=0; char room_kind; int discount=0; char c; int out=0; int enter=0; int Days=0; double TotalPrice=0; printf ("Welcome to Turbo_C Hotel.\n\n"); printf ("How many people you are?\n\n"); scanf ("%lf", &People_including_kids); if (People_including_kids < 0) { /*if the tottal number of people including kids is not possitive we end the program*/ printf ("ERROR\n"); return 0; } if (People_including_kids != (int)People_including_kids) { /*if the the tottal number of people is a fraction we end the program*/ printf ("ERROR\n"); return 0; } else { printf ("Are you a VIP client?\n\n"); } scanf ("%c", &is_a_vip); if (is_a_vip == 'Y') { discount=1 } /*if he is a VIP client we store that answer as discount=1*/ else if (is_a_vip == 'N') { discount=0 } else { printf ("ERROR"); /*if he didnt enter Y or N we end the program*/ return 0; } printf ("How many kids are involved?\n\n"); scanf ("%lf", &kids_invovled); if (kids_invovled < 0) { /*once again, checking that the number of kids is possitive and not a fraction*/ printf ("ERROR\n"); return 0; } if (kids_invovled != (int)kids_invovled) { printf ("ERROR\n"); return 0; } if (kids_invovled > People_including_kids) { /*checking if the number of kids is bigger than the number of the tottal people*/ printf ("ERROR\n"); return 0; } else { people_not_including_kids = People_including_kids - kids_invovled; /*number of people not including kids, because kids dont pay*/ } printf ("What kind of room would you like to reserve?\n\n"); scanf ("%c", &room_kind); if (room_kind == 'A') { PriceForDay = 120} else if (room_kind == 'B') { PriceForDay = 140} else if (room_kind == 'C') { PriceForDay = 220} else { printf ("ERROR"); return 0; } printf ("What is your staying schedule?\n\n"); scanf("%d%c%d", &enter, &c, &out); /*must enter days this way: 1-5, 6-3 etc.*/ if (c != '-'){ printf("ERROR\n"); return 0; } if ((enter < 1) || (enter> 7) || (out < 1) || (out > 7)){ printf("ERROR\n"); return 0; } if (enter < out){ Days = out -enter + 1; TotalPrice = Days * PriceForDay * people_not_including_kids; if ((enter <= 6)&& (out == 7) && (discount == 0)) TotalPrice += 45*people_not_including_kids; else if ((enter <= 6)&& (out == 7) && (discount == 1)) TotalPrice += 0.93*45*people_not_including_kids; else { for (; enter <= out; enter ++){ if ((enter == 6) && (discount == 0)) TotalPrice += 20*people_not_including_kids; else if ((enter == 6) && (discount == 1)) TotalPrice += 0.93*20*people_not_including_kids; if ((enter == 7) && (discount == 0)) TotalPrice += 30*people_not_including_kids; else if ((enter == 7) && (discount == 1)) TotalPrice += 0.93*30*people_not_including_kids; } } } if (enter == out){ Days = 1; TotalPrice = PriceForDay * people_not_including_kids; if ((enter == 6) && (discount == 0))TotalPrice += 20*people_not_including_kids; else if ((enter == 6) && (discount == 1))TotalPrice += 0.93*20*people_not_including_kids; if ((enter == 7) && (discount == 0))TotalPrice += 30*people_not_including_kids; else if ((enter == 7) && (discount == 1))TotalPrice += 0.93*30*people_not_including_kids; } if (enter > out){ Days = (7 -enter) + out + 1; TotalPrice = Days * PriceForDay * people_not_including_kids; if ((enter <= 6) && (discount == 0))TotalPrice += 45*people_not_including_kids; else if ((enter <= 6) && (discount == 1))TotalPrice += 0.93*45*people_not_including_kids; else { for (; enter <= out; enter ++){ if ((enter == 6) && (discount == 0)) TotalPrice += 20*people_not_including_kids; else if ((enter == 6) && (discount == 1)) TotalPrice += 0.93*20*people_not_including_kids; if ((enter == 7) && (discount == 0)) TotalPrice += 30*people_not_including_kids; else if ((enter == 7) && (discount == 1)) TotalPrice += 0.93*30*people_not_including_kids; } } } if (discount == 1){ TotalPrice = 0.8*TotalPrice } /*at the end - if its a VIP client we take off 20% from the FINAL price*/ printf ("Your bill is: %lf\n\n" ,TotalPrice); else { printf ("Your bill is: %lf\n\n" ,TotalPrice); printf ("If you choose to join our VIP club, you will be charged with 400$ but enjoy the club members reduction, Tottal bill: %lf\n\n" , ... ); /*if its not a VIP client, we show him what discounds he could have gotten (7%off for the weekend and 20% off at the end) + 400$ for joining*/
לצורך הדגמה מוחשית יותר, הפלט אמור להראות כך:
[התמונה הבאה מגיעה מקישור שלא מתחיל ב https ולכן לא הוטמעה בדף כדי לשמור על https תקין: http://www.upit.ws/uploads/6e20da838c824.JPG]
הסבתכתי קשות עם הלולאות של הימים, כי מה שקורה הוא שבהתחלה מכניסים את מספר האנשים, אחרי זה את מספר הילדים ואז יש חישוב מהיר של כמה אנשים לא כולל ילדים יש, כי הם אלו שמשלמים. אחרי זה יש שאלה האם אתה לקוח VIP, כשמה שלקוח VIP מקבל זה הנחה של 7% במחירים של הסופ"שים (ימים 6-7 כאשר ליום שישי משלמים עוד 20$, לשבת 30% ולשישי+שבת 45$) ובסוף בסוף הנחה של 20% על הכל כולל הכל.
החל מהשאלה What is your staying schedule? יש כל מיני מקרים של בחירת ימים בבית מלון כשעבור כל יום בבית מלון משלמים מחיר מסויים עבור כל אורח (מספר אורחים(לא כולל ילדים) * מספר ימים * מחיר ליום של החדר), ויש תוספת של מחיר עבור הסופי שבוע שבה יש מצב טריקי בו ה VIP מקבלים הנחה של 7% ואני לא בטוח אם כתבתי נכון את ה else if למקרה הזה. אני אשמח אם תוכלו להעביר קריאה לראות אם זה תקין.. אני יודע שזה לא הקוד האופטימלי אבל כרגע אני רק רוצה תכנית שרצה כמו שצריך מההתחלה ועד הסוף.
****
בסוף,בהערה הכתומה האחרונה, ישנה הבעיה האחרונה בקוד.
אם אתה לקוח VIP הכל נחמד ויפה, אני מוריד לך 20%, מדפיס לך את החשבון ולך לחדר.
אבל אם אתה לא לקוח VIP.. אני מדפיס לך את החשבון ואז אומר לך-
אם היית בוחר להצטרף למועדון, היית משלם עוד 400$ על ההצטרפות אבל מקבל את כל ההנחות של הלקוח VIP וזה היה יוצא לך: ...
איך אני אכתוב את זה? הרי לא אכסנתי את המחיר הסופי של הלקוח VIP במשתנה כלשהו.. וכל החישוב של המחיר הסופי של לקוח VIP בכלל לא מחושב במקרה שכזה! (זאת הבעיה העיקרית והאחרונה שלי בקוד, בהנחה שכל מה שנכתב לפניו יעבוד לדעתכם)
אני חייב להגיש את זה מחר בבוקר
ואני חייב את העזרה שלכם..
|