# تصحيح كود برنامج سى ( ارجو المساعدة )

[FONT=‘Times New Roman’][COLOR=#000000]
السلام عليكم و رحمة الله و بركاته …

عندى برنامج فى لغة السى , و قد قمت بحله و لكن توجد اخطاء و لم استطع حلها …

سأرفق لكم الكود الذى كتبته و ايضا السؤال و ارجوا منك الساعدة بتصحصح الاخطاء فى اسرع وقت ممكن لو تكرمتوا …

السؤال :

local integer variables: itemstock1, itemstock2 and itemstock3. These variables represent
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

void menu(int stock1, int stock2, int stock3)
[LEFT]displays a menu for the user to

select a choice from, listing the menu item of each stock, the item price, and an "out of
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

user enters an invalid amount, they are re-prompted until valid input is entered. The valid
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

relevant itemstock variable. If the item is out of stock, an error message is printed,
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;

return 0;
}

**
int item;
printf("

Welcome to the Online snackShack");
printf(“
”);
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(“
scanf(”%d”,&item);

if ( item < min || item > max )
**
}
else
**
while ( item == 4 )
**
if ( itemstock1 == 0 )
**
printf ( " Sorry, item is out of stock ");
}
else
**
if (item == 1) /* If the first item is selected*/
vend ( 2 ,&itemstock1 );
}

if ( itemstock2 == 0 )
**
printf ( " Sorry, item is out of stock ");
}
else
**
if (item == 2)
vend ( 4 ,&stock2 ); /* If the first item is selected*/
**

if ( itemstock3 == 0 )
**
printf ( " Sorry, item is out of stock ");
}
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]