לוגו אתר Fresh          
 
 
  אפשרות תפריט  ראשי     אפשרות תפריט  צ'אט     אפשרות תפריט  מבזקים     אפשרות תפריט  צור קשר     חץ שמאלה ‎print ‎"Hello World!"; if‎ ‎not rules.‎know ‎then rules.‎read(); חץ ימינה  

לך אחורה   לובי הפורומים > מחשבים > תכנות ובניית אתרים
שמור לעצמך קישור לדף זה באתרי שמירת קישורים חברתיים
תגובה
 
כלי אשכול חפש באשכול זה



  #1  
ישן 16-12-2008, 18:04
צלמית המשתמש של *~.Shush.~*
  משתמשת נקבה *~.Shush.~* *~.Shush.~* אינו מחובר  
 
חבר מתאריך: 10.10.06
הודעות: 64
C Hotel תכנית ארוכה ומייגעת

אהלן אנשים, מה קורה?

אז ככה, יש לי תרגיל לכתוב תכנית של "בית מלון". משהו בסגנון של קנאטרי קלאב בטורקיה רק לא הכל כלול..

התכנית שלכם תברך את המשתמש, תציג את השאלות הבאות בפלט ותצפה לתשובה מהלקוח עבור כל שאלה:


הערה: לפני קליטת תו CHAR יש להשתמש ב-
while(getchar()!='\n'); qqq
(qqq סתם לסידור השורה)
מספרים עם שברים מדפיסים עד 2 ספרות עשרוניות

1) מהו מספר האנשים השוהים בחדר כולל מספר הילדים (מספר שלם וחיובי בלבד). אם מוכנס קלט שהוא לא מספר חיובי תודפס הודעות ERROR ותסתיים התכנית.
לדוגמא:

How many people you are?

4

2) האם הלקוח הוא לקוח VIP. אם כן הוא מקבל הנחה של 20% על החשבון הסופי. אם הוא לקוח VIP הוא יכניס Y ואם לא יכניס N. לקוח VIP יהנה מהטבות נוספות שיפורטו בהמשך.. אם לא מוכנס תו Y או N תודפס הודעת שגיאה ERROR ותסתיים התכנית!
לדוגמא:

Are you a vip client?

Y


[התמונה הבאה מגיעה מקישור שלא מתחיל ב https ולכן לא הוטמעה בדף כדי לשמור על https תקין: http://www.upit.ws/uploads/213e0208d9849.JPG]

(עכשיו זה נראה קצת יותר רציני
[התמונה הבאה מגיעה מקישור שלא מתחיל ב https ולכן לא הוטמעה בדף כדי לשמור על https תקין: http://www.fxp.co.il/images/smilies2/smile.gif]
)


[התמונה הבאה מגיעה מקישור שלא מתחיל ב https ולכן לא הוטמעה בדף כדי לשמור על https תקין: http://www.upit.ws/uploads/4375a1608f106.JPG]


דוגמת הרצה:


How many people you are?

4

Are you a vip client?

Y

How many kids are invovled?

2

What kind of room would you like?

B

What is your staying schedule?

1-6

Your bill is: 1773.76
If you choose to join the VIP club you will be charged 400$ but your total bill will be: 1720

אני יודע שזה קצת הרבה ואני אשמח לכל חלק מהתכנית שתוכלו לכתוב
[התמונה הבאה מגיעה מקישור שלא מתחיל ב https ולכן לא הוטמעה בדף כדי לשמור על https תקין: http://www.fxp.co.il/images/smilies2/bot.gif]
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
  #7  
ישן 20-12-2008, 16:18
  kibatron kibatron אינו מחובר  
 
חבר מתאריך: 16.10.08
הודעות: 19
בתגובה להודעה מספר 5 שנכתבה על ידי kibatron שמתחילה ב "אתה שומע אחי שפת C לא בא לי..."

הנה התוכנית בHASKELL בלי הג'יפה של הקלט. תשווה תאורך לתוכנית C.

קוד PHP:
 data Day Sunday
           
Monday
           
Tuesday
           
Wednesday
           
Thursday
           
Friday
           
Saturday
           deriving 
(EqEnumShow)

data Customer Regular
                
VIP
                deriving 
(Show)

data Room A
            
B
            
C
            deriving 
(Show)


makeDayList start end start == end = [start]
                     | 
otherwise start : (makeDayList (toEnum ((fromEnum start 1) `mod7)::Dayend)

stayContainsDay day dayList length (filter (\thisDay -> thisDay == daydayList) == 1

stayContainsFriday 
stayContainsDay Friday
stayContainsSaturday 
stayContainsDay Saturday

calculateDayBill A numPersons 
120 numPersons
calculateDayBill B numPersons 
140 numPersons
calculateDayBill C numPersons 
220 numPersons

calculateWeekendBill numPersons dayList
    
| (stayContainsFriday dayList) && (stayContainsSaturday dayList)  = 45 numPersons
    
| (stayContainsFriday dayList) = 20  numPersons
    
| (stayContainsSaturday dayList) = 30 numPersons
    
otherwise 0


calculateStayBill customerType roomType numPersons dayList 
=
    
let
        weekdayBill 
fromInteger(toInteger(calculateDayBill roomType numPersons * (length dayList)))
        
weekendBill fromInteger(toInteger(calculateWeekendBill numPersons dayList))
    
in
   
case customerType of
            Regular 
-> weekdayBill weekendBill
            VIP 
-> 0.8 * (weekdayBill 0.93 weekendBill


כל מה שעושים זה מריצים תפונקציה ככה
calculateStayBill VIP A 2 (makeDayList Sunday Friday)
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
  #8  
ישן 19-12-2008, 09:04
צלמית המשתמש של *~.Shush.~*
  משתמשת נקבה *~.Shush.~* *~.Shush.~* אינו מחובר  
 
חבר מתאריך: 10.10.06
הודעות: 64
בתגובה להודעה מספר 1 שנכתבה על ידי *~.Shush.~* שמתחילה ב "C Hotel תכנית ארוכה ומייגעת"

אוקיי אני כתבתי את התכנית עד הסעיף ה 5 שמדבר על הימים



[התמונה הבאה מגיעה מקישור שלא מתחיל ב https ולכן לא הוטמעה בדף כדי לשמור על https תקין: http://www.upit.ws/uploads/34d21f15e31ee.JPG]


ז
אני צריך לכתוב קוד לחלק הזה של התרגיל.. ניתן להתעלם מהחלק שמדבר על לקוחות VIP וסוגי חדרים זה קשור יותר לסעיפים קודמים.

אין לי שמץ איך לכתוב את הקטע הזה עם הימים.. התכנית צריכה גם לזהות אם רק יום שישי כלול בהזמנה ולעשות ~פעולה כלשהי 1~, לזהות אם רק יום שבת כלול ואז לבצע ~פעולה כלשהי 2~ , לראות אם הימים כוללים גם את שישי וגם את שבת ולבצע ~פעולה כלשהי 3~ ולקבל הכנסת מספרים רק בין 1 ל 7 כשהיא יודעת לחשב לפי ההכנסת מספרים כמה ימים הוא שהה במלון (זה חשוב לשם חישוב החשבון בסוף) ועוד לקלוט הכנסת ימים כמו 7-2 (שבת עד שני) ולספור את זה בתור 3 ימים..

איך ?!
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
  #9  
ישן 19-12-2008, 11:15
  Dragonion Dragonion אינו מחובר  
 
חבר מתאריך: 22.08.08
הודעות: 310
בתגובה להודעה מספר 8 שנכתבה על ידי *~.Shush.~* שמתחילה ב "אוקיי אני כתבתי את התכנית עד..."

בתור התחלה, תבדוק ישר עם שני המספרים גדולים מ 7 או קטנים מ 1 ועם כן אז תעשה משהו בנידון (ERROR כמו שכתבו לך).

עריכה: שכחתי שאתה צריך גם שישי-שבת ספציפי, אני מוסיף את זה.
עריכה שנייה: הוספתי ושמתי קוד סופי.

קוד PHP:
 int a,b;

cout<<"Please enter the day you will come.\n";
cin >> a;
if(
|| 1// cout an error, or something
cout<<"Please enter the day you will leave.\n";
cin >> b;
if(
|| 1// cout an error, or something

if(== b)
{
    
// אפשר גם ישר להוסיף פה שהלקוח ישהה רק יום אחד
    
if(a==6// רק יום שישי
    
if(a==7// רק שבת
}
else if(
a==&& a==7// שישי-שבת ואפשר גם ישר להוסיף שהלקוח ישהה שני ימים 

עכשיו בשביל לבדוק כמה ימים האדם ישהה, יש שלושה אפשרויות של יחסים:
a > b // from week to week
a < b // the same week
a == b // one day
מכאן זה פשוט חישוב של ימים
קוד PHP:
 int days;

if(
b)  days b// שבע לא לוקח בחשבון את שבת אז מוסיפים אחד ויוצא שמונה
if(b)  days b+1-a;     // מכיוון שבי גדול מאי, אפשר פשוט לעשות הפרש אבל עוד פעם זה לא לוקח בחשבון את שבת אז מוסיפים אחד
if(== bdays 1;         // יום אחד 

ובסופו של דבר זה מה שיצא
קוד PHP:
 int a,b,days;

// הוספתי תויות בשביל שיוכלו לחזור ולהכניס נתונים נכונים
enterDayA:
cout<<"Please enter the day you will come.\n";
cin >> a;
if(
|| 1)
{
    
cout<<"Error: only numbers between 1 and 7 (both included) are allowed.\n";
    goto 
enterDayA
}
enterDayB:
cout<<"Please enter the day you will leave.\n";
cin >> b;
if(
|| 1)
{
    
cout<<"Error: only numbers between 1 and 7 (both included) are allowed.\n";
    goto 
enterDayB
}

if(
== b)
{
    
days 1;
    if(
a==6){/* only Friday */}
    else if(
a==7){/* only Saturday  */}
}
else if(
a==&& a==7)
{
    
days 2;
    
/* Friday and Saturday */
}
else
{
     if(
b)  days b;
     else if(
b)  days b+1-a;




נערך לאחרונה ע"י Dragonion בתאריך 19-12-2008 בשעה 11:45.
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
  #10  
ישן 20-12-2008, 09:18
  sigsig sigsig אינו מחובר  
 
חבר מתאריך: 23.11.07
הודעות: 187
בתגובה להודעה מספר 8 שנכתבה על ידי *~.Shush.~* שמתחילה ב "אוקיי אני כתבתי את התכנית עד..."

הנה עוד דרך לעשות את החישוב של הימים (ואם היה לך מושג כמה זמן כבר לא כתבתי ב-C טהור...):


קוד PHP:
 #include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>

#define IS_VALID_DAY(x) ((x) >= 1 && (x) <= 7)
#define SET_IF_DAY(day, field) if(this_day == (day)) (field) = true

struct days_info
{
        
unsigned char number_of_days;
        
bool is_friday_included;
        
bool is_saturday_included;
};

struct days_info *get_days_info(unsigned char start_dayunsigned char end_day)
{
        
// Check validity of days
        
if(!IS_VALID_DAY(start_day) || !IS_VALID_DAY(end_day))
                return 
NULL;

        
// Change from range of 1-7 to a range of 0-6 (which is modulo 7 arithmetic)
        
start_day--;
        
end_day--;

        
// Allocate structure memory and initialize to NULL
        
struct days_info *info = (struct days_info *)malloc(sizeof(struct days_info));
        if(!
info)
                return 
NULL;
        
memset(info0sizeof(struct days_info));

        
// For each day in the range...
        
unsigned char this_day start_day;
        do
        {
                
info->number_of_days++;                     // ... increase number of days in stay
                
SET_IF_DAY(5info->is_friday_included);   // ... set Friday if necessary
                
SET_IF_DAY(6info->is_saturday_included); // ... set Saturday if necessary
                
this_day = (this_day 1) % 7;             // ... move to next day in week
        
}   while(this_day != end_day);

        return 
info;
}


int main(int argcchar** argv)
{
        
// Start and end days of stay - these should come as input
        
unsigned char start_day 2;
        
unsigned char end_day 7;

        
// Get a days_info struct with the relevant data
        
struct days_info *hotel_stay get_days_info(start_dayend_day);
        if(!
hotel_stay)
                return(
1);      // If the function returned null - this is some sort of error

        // Do something with the data
        
printf("Number of days:  %d,  Stay includes Friday:  %d,  Stay includes Saturday:  %d\n",
                
hotel_stay->number_of_dayshotel_stay->is_friday_includedhotel_stay->is_saturday_includ
ed
);

        
// Don't forget to free the allocated struct!!
        
free(hotel_stay);

תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
  #11  
ישן 19-12-2008, 12:04
  Dragonion Dragonion אינו מחובר  
 
חבר מתאריך: 22.08.08
הודעות: 310
בתגובה להודעה מספר 1 שנכתבה על ידי *~.Shush.~* שמתחילה ב "C Hotel תכנית ארוכה ומייגעת"

סליחה לא הבנתי אותך נכון לגבי שישי-שבת.
קוד PHP:
 int a,b,days;

enterDayA:
cout<<"Please enter the day you will come.\n";
cin >> a;
if(
|| 1)
{
    
cout<<"Error: only numbers between 1 and 7 (both included) are allowed.\n";
    goto 
enterDayA
}
enterDayB:
cout<<"Please enter the day you will leave.\n";
cin >> b;
if(
|| 1)
{
    
cout<<"Error: only numbers between 1 and 7 (both included) are allowed.\n";
    goto 
enterDayB
}

if(
== b)
{
    
days 1;
    if(
a==6)      {/* Friday is included */}
    else if(
a==7) {/* Saturday is included */}
}
else
{
    if(
b)
    { 
        
days b;
        if(
6){/* Friday and Saturday are included */}
        else if(
== 7)
        {
            if(
== 6){/* Friday and Saturday are included */}
            else      {
/* Saturday is included */}
        } 
    else if(
b)
    {   
        
days b-a+1;
        if(
5)
        {
            if(
b==7){/* Friday and Saturday are included */}
            else    {
/* Friday is included */}
        }       
    }



תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
  #12  
ישן 20-12-2008, 08:55
צלמית המשתמש של *~.Shush.~*
  משתמשת נקבה *~.Shush.~* *~.Shush.~* אינו מחובר  
 
חבר מתאריך: 10.10.06
הודעות: 64
בתגובה להודעה מספר 1 שנכתבה על ידי *~.Shush.~* שמתחילה ב "C Hotel תכנית ארוכה ומייגעת"

חבר'ה תודה רבה על הסבלנות, במיוחד לך 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=/*if he is a VIP client we store that answer as discount=1*/
 
else if (is_a_vip == 'N') { discount=}
 
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 (!= '-'){
 
                
printf("ERROR\n");
 
                return 
0;
 
        }
 
        if ((
enter 1) || (enter7) || (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 <= outenter ++){
 
                             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 = (-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 <= outenter ++){
 
                             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 בכלל לא מחושב במקרה שכזה! (זאת הבעיה העיקרית והאחרונה שלי בקוד, בהנחה שכל מה שנכתב לפניו יעבוד לדעתכם)



אני חייב להגיש את זה מחר בבוקר
ואני חייב את העזרה שלכם..
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
  #16  
ישן 20-12-2008, 15:41
צלמית המשתמש של *~.Shush.~*
  משתמשת נקבה *~.Shush.~* *~.Shush.~* אינו מחובר  
 
חבר מתאריך: 10.10.06
הודעות: 64
בתגובה להודעה מספר 15 שנכתבה על ידי sigsig שמתחילה ב "אני לא ממש מצליח לעקוב אחרי..."

קוד 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 Extra=0;
double TotalPrice=0;
double TotalPrice_vip=0;
int TotalPrice_normal=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"); 


הקשבתי לעצתך.
הבעיה עכשיו היא בהרצה. זה כתוב לי
Welcome to Turbo_C Hotel

Are you a VIP client?

וברגע שאני מכניס מספר, גם אם הוא שלם וחיובי, זה מסיים את התכנית ולא כותב את השאלה הבאה! למה?

נערך לאחרונה ע"י *~.Shush.~* בתאריך 20-12-2008 בשעה 15:43.
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
  #18  
ישן 20-12-2008, 16:50
צלמית המשתמש של *~.Shush.~*
  משתמשת נקבה *~.Shush.~* *~.Shush.~* אינו מחובר  
 
חבר מתאריך: 10.10.06
הודעות: 64
בתגובה להודעה מספר 17 שנכתבה על ידי sigsig שמתחילה ב "אתה בטוח שזו כל התוכנית? כי..."

סליחה! אני בלבלתי בין השאלות!
קודם כל התכנית בשלמותה:

קוד 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 Extra=0;
double TotalPrice=0;
double TotalPrice_vip=0;
int TotalPrice_normal=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 (!= '-'){
                
printf("ERROR\n");
                return 
0;
        }
        if ((
enter 1) || (enter7) || (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)) Extra 45*people_not_including_kids;
                else {
                        for (; 
enter <= outenter ++){
                             if (
enter == 6Extra 20*people_not_including_kids;
                             if (
enter == 7Extra 30*people_not_including_kids;
                                                     }
                     }
        }
        if (
enter == out){
                
Days 1;
                
TotalPrice PriceForDay;
                if (
enter == 6)Extra 20*people_not_including_kids;
                if (
enter == 7)Extra 30*people_not_including_kids;
        }
        if (
enter out){
                
Days = (-enter) + out 1;
                
TotalPrice Days PriceForDay people_not_including_kids;
                if (
enter <= 6)Extra45*people_not_including_kids;
                else {
                        for (; 
enter <= outenter ++){
                             if (
enter == 6Extra 20*people_not_including_kids;
                             if (
enter == 7Extra 30*people_not_including_kids;
                        }
                }
     } 
 
TotalPrice_vip = (TotalPrice Extra*0.93)*0.8;
TotalPrice_normal TotalPrice Extra;
 
 
if (
discount == 1){ /*VIP client*/
             
printf ("Your bill is: %lf\n\n" ,TotalPrice_vip); 
             }            
else {             
/*Not VIP*/
     
printf ("Your bill is: %lf\n\n" ,TotalPrice_normal); 
     
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" TotalPrice_vip+400 );
     }
     return 
0;
     
/*if its not a VIP client, we show him what discounds he could of gotten (7%off for the weekend and 20% off at the end) + 400$ for joining*/             



אם תריץ אותה (בטורבו C) תראה שזה שואל את השאלה הראשונה (How many people you are?), ואם תכניס מספר שהוא תקין נגיד 5 התכנית תסתיים פשוט במקום להמשיך הלאה לשאלה הבאה (are you a vip client?)
ואני ממש לא מבין למה זה קורה

נערך לאחרונה ע"י *~.Shush.~* בתאריך 20-12-2008 בשעה 16:53.
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
תגובה

כלי אשכול חפש באשכול זה
חפש באשכול זה:

חיפוש מתקדם
מצבי תצוגה דרג אשכול זה
דרג אשכול זה:

מזער את תיבת המידע אפשרויות משלוח הודעות
אתה לא יכול לפתוח אשכולות חדשים
אתה לא יכול להגיב לאשכולות
אתה לא יכול לצרף קבצים
אתה לא יכול לערוך את ההודעות שלך

קוד vB פעיל
קוד [IMG] פעיל
קוד HTML כבוי
מעבר לפורום



כל הזמנים המוצגים בדף זה הם לפי איזור זמן GMT +2. השעה כעת היא 03:19

הדף נוצר ב 0.54 שניות עם 10 שאילתות

הפורום מבוסס על vBulletin, גירסא 3.0.6
כל הזכויות לתוכנת הפורומים שמורות © 2024 - 2000 לחברת Jelsoft Enterprises.
כל הזכויות שמורות ל Fresh.co.il ©

צור קשר | תקנון האתר