Can anyone add some codes in my program so that it could output a receipt which would display the name of the items bought with their price..:)
#include<stdio.h>
int item_details ();
int payment (int x);
int add_item (int x);
int main ()
{
int choice,price;
printf("Enter 1 to buy.\n\n");
printf("Enter Choice: ");
scanf("%d",&choice);
switch(choice){
case 1:
price=item_details ();
printf("\t\t\tTotal payment is %d\n", price);
add_item (price);}
}
int item_details ()
{
int itemcode, price,piece;
printf("\nEnter itemcode: ");
scanf("%d",&itemcode);
if( itemcode != 100 && itemcode != 200 && itemcode != 300 && itemcode != 400 &&
itemcode != 500)
do{
printf("Itemcode does not exist!\n");
printf("\nReEnter Itemcode: ");
scanf("%d", &itemcode);}
while ( itemcode != 100 && itemcode != 200 && itemcode != 300 && itemcode != 400 &&
itemcode != 500);
while ( itemcode != 100 && itemcode != 200 && itemcode != 300 && itemcode != 400 &&
itemcode != 500);
printf("How many pieces? ");
scanf("%d", &piece);
switch(itemcode){
case 100:
printf("\t\t\tCellphone1....................P4000\n");
price=4000*piece;
return price;
break;
case 200:
printf("\t\t\tCellphone2....................P5000\n");
price=5000*piece;
return price;
break;
case 300:
printf("\t\t\tCellphone3....................P6000\n");
price=6000*piece;
return price;
break;
case 400:
printf("\t\t\tCellphone4....................P7000\n");
price=7000*piece;
return price;
break;
case 500:
printf("\t\t\tCellphone5....................P8000\n");
price=8000*piece;
return price;
break;
default:
printf("Itemcode does not match!\n");
break;
}
}
int add_item (int x)
{
int price;
char choice;
price=x;
printf("Add another item?y/n ");
scanf("%s", &choice);
switch(choice){
case 'y':
price=price+item_details ();
printf("\t\t\tTotal payment is %d\n", price);
add_item(price);
case 'n':
payment(price);
}
}
int payment(int x)
{
char choice,count;
float cash_recieved,price,change;
price=x;
printf("\nEnter cash recieved: ");
scanf("%f",&cash_recieved);
if(cash_recieved<price)
{printf("Insufficient money!\n");}
else
{change=cash_recieved-price;
printf("\nChange is %.2f", change);}
getchar ();
getchar ();
}