[FONT=‘Times New Roman’][COLOR=#000000]
السلام عليكم و رحمة الله و بركاته …
عندى برنامج فى لغة السى , و قد قمت بحله و لكن توجد اخطاء و لم استطع حلها …
سأرفق لكم الكود الذى كتبته و ايضا السؤال و ارجوا منك الساعدة بتصحصح الاخطاء فى اسرع وقت ممكن لو تكرمتوا …
السؤال :
the number of items in stock of item1, item2 and item3 respectively. Initially, there is
two of each item in stock. You may also use additional variables for other purposes.
Your progam must contain and make sensible use of the following functions (do not
add any additional parameters to the functions, and do not create additional functions):
void menu(int stock1, int stock2, int stock3)
[LEFT]displays a menu for the user to
stock" message if the item is out of stock.
int getnum(int min, int max)
[/left]
[LEFT]reads an integer within the range min…max. If the
input is then returned from the function.
void vend(int cost, int* istock)
[/left]
[LEFT]accepts the cost of an item, and a pointer to the
otherwise the user is prompted to enter money. If insufficient money is entered, and
error message is printed, otherwise the item is vended (meaning the stock of that item is
reduced) and change (if any) is given.
شاكرا لكم حسن تعاونكم … و جزاكم الله الف خير …
ملاحظة : البرنامج عبارة عن مكين
كود البرنامج :::
#include <stdio.h>
int main(void)
**
int itemstock1 = 2;
int itemstock2 = 2;
int itemstock3 = 2;
menu(itemstock1, itemstock2, itemstock3);
return 0;
}
void menu(int stock1,int stock2,int stock3)
**
int item;
printf("
Welcome to the Online snackShack");
printf(“
Menu
”);
printf(“
1:Crushed Crisp ($2)”);
if ( stock1 =< 0 )
**
printf ( " [out of stock] " );
}
printf(“
2:MeltedMunchies ($4) “);
if ( stock2 =< 0 )
**
printf ( " [out of stock] " );
}
printf(“
3:FlatFizz ($3)”);
if ( stock3 =< 0 )
**
printf ( " [out of stock] " );
}
printf(“
4: Exit
”);
itme = getnum(1,4);
}
int getnum(int min,int max)
**
int item;
printf(“
Please Enter your selection :”);
scanf(”%d”,&item);
if ( item < min || item > max )
**
menu( stock1, stock2, stock3) ;
}
else
**
while ( item == 4 )
**
if ( itemstock1 == 0 )
**
printf ( " Sorry, item is out of stock ");
menu( stock1, stock2, stock3) ;
}
else
**
if (item == 1) /* If the first item is selected*/
vend ( 2 ,&itemstock1 );
}
if ( itemstock2 == 0 )
**
printf ( " Sorry, item is out of stock ");
menu( stock1, stock2, stock3) ;
}
else
**
if (item == 2)
vend ( 4 ,&stock2 ); /* If the first item is selected*/
**
if ( itemstock3 == 0 )
**
printf ( " Sorry, item is out of stock ");
menu(int stock1,int stock2,int stock3) ;
}
else
**
if (item == 3) /* If the first item is selected*/
vend ( 3 ,&stock3 );
}
}
}
return item;
}
void vend ( int cost , int *istock )
**
int change ;
int price ;
printf ( " Please enter amount : ");
scanf ( " %d ",& price );
if (price == cost)
**
printf ( " Vending item “);
*istock = *istock - 1;
}
if ( price < cost )
**
printf (” Insuficient funds. Refunding money ");
}
else
**
change = price - cost;
prinf ( " Giving change of %d ",change );
}
}
[/left]
[/color][/font]