Can't find the mistake in the program

Mahmood619

Mahmood619

@mahmood619-XmMVoT Oct 23, 2024
[FONT=&amp]1. [/FONT]Write a complete program based on the following requirements:
· In the main( ) function :
[FONT=&amp]o [/FONT]Ask the user whether they want to continue executing the program.
[FONT=&amp]o [/FONT]
[FONT=&amp]o [/FONT]Repeat these processes as long as the choice is ‘Y’:
§ Call function menu() to display the menu.
§ Get the user’s name, choice and quantity.
§ Call function get_item(…) and send choice to get the item name.
§ Call function get_price(…) and send choice to get the price.
§ Calculate payment by multiplying price with quantity.
§ Keep track of how many of each item has been sold.
§ Call function display(…) and send appropriate variables to be displayed on screen. [Note: Refer to sample output screen]

[FONT=&amp]o [/FONT]If their choice is NOT ‘Y’:
§ Display the summary by showing the total purchase and also how many of each item has been sold. [Note: Refer to sample output screen]

· In function menu() :
[FONT=&amp]o [/FONT]Display the menu as shown in the output screen.

· In function get_item(…) :
[FONT=&amp]o [/FONT]Identify the item name using switch-case statement based on the choice.
[FONT=&amp]o [/FONT]Return the item name.

· In function get_price(…) :
[FONT=&amp]o [/FONT]Identify the price of the item using switch statement based on the choice.
[FONT=&amp]o [/FONT]Return the item price.

· In function display(…) :
[FONT=&amp]Display all information as shown in the output screen.

[/FONT] Sample output screen
[TABLE="class: MsoNormalTable"]
[TR]
[TD="width: 584"] [TABLE="align: left"]
[TR]
[TD="width: 243"][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[/TABLE]
[FONT=&quot] [/FONT]

[FONT=&quot]Would you like to continue ? : y[/FONT]

[FONT=&quot] [/FONT]
[FONT=&quot]----------------------------------------------------[/FONT]

[TABLE]
[TR]
[TD="width: 178, bgcolor: white"] [TABLE]
[TR]
[TD] Display menu by calling function menu()

[/TD]
[/TR]
[/TABLE]
[/TD]
[/TR]
[/TABLE]
[FONT=&quot]- WELCOME TO MYCAR ACCESORIES -[/FONT]
[FONT=&quot]----------------------------------------------------[/FONT]
[FONT=&quot] 1. Pioneer MP3 Player [ $ 350.00 ][/FONT]
[FONT=&quot] 2. MOMO Sports Steering [ $ 770.00 ][/FONT]
[FONT=&quot] 3. MOMO Gear Knob [ $ 150.00 ][/FONT]
[FONT=&quot]----------------------------------------------------[/FONT]
[TABLE]
[TR]
[TD="width: 299, bgcolor: white"] [TABLE]
[TR]
[TD] Ask user to enter name, choice and quantity

[/TD]
[/TR]
[/TABLE]
[/TD]
[/TR]
[/TABLE]
[FONT=&quot]Enter name : Usha Vellappan[/FONT]

[FONT=&quot]Enter choice : 2[/FONT]
[FONT=&quot]Enter quantity : 3[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]----------------------------------------------------[/FONT]

[FONT=&quot]- RECEIPT OF PURCHASE -[/FONT]
[TABLE]
[TR]
[TD="width: 179, bgcolor: white"] [TABLE]
[TR]
[TD] Display information by calling function display()

[/TD]
[/TR]
[/TABLE]
[/TD]
[/TR]
[/TABLE]
[FONT=&quot]----------------------------------------------------[/FONT]
[FONT=&quot]Name : Usha Vellappan[/FONT]
[FONT=&quot]Item : MOMO Sports Steering[/FONT]
[FONT=&quot]Price : RM 770.00[/FONT]
[FONT=&quot]Quantity : 3[/FONT]
[FONT=&quot]Payment : RM 2310.00[/FONT]
[FONT=&quot]----------------------------------------------------[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]Would you like to continue ? : y[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]----------------------------------------------------[/FONT]
[FONT=&quot]- WELCOME TO MYCAR ACCESORIES -[/FONT]
[FONT=&quot]----------------------------------------------------[/FONT]
[FONT=&quot] 1. Pioneer MP3 Player [ $ 350.00 ][/FONT]
[FONT=&quot] 2. MOMO Sports Steering [ $ 770.00 ][/FONT]
[FONT=&quot] 3. MOMO Gear Knob [ $ 150.00 ][/FONT]
[FONT=&quot]----------------------------------------------------[/FONT]
[FONT=&quot]Enter name : Naziffa Raha[/FONT]
[FONT=&quot]Enter choice : 2[/FONT]
[FONT=&quot]Enter quantity : 1[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]----------------------------------------------------[/FONT]
[FONT=&quot]- RECEIPT OF PURCHASE -[/FONT]
[FONT=&quot]----------------------------------------------------[/FONT]
[FONT=&quot]Name : Naziffa Raha[/FONT]
[FONT=&quot]Item : MOMO Sports Steering[/FONT]
[FONT=&quot]Price : RM 770.00[/FONT]
[FONT=&quot]Quantity : 1[/FONT]
[FONT=&quot]Payment : RM 770.00[/FONT]
[FONT=&quot]----------------------------------------------------[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]Would you like to continue ? : y[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]----------------------------------------------------[/FONT]
[FONT=&quot]- WELCOME TO MYCAR ACCESORIES -[/FONT]
[FONT=&quot]----------------------------------------------------[/FONT]
[FONT=&quot] 1. Pioneer MP3 Player [ $ 350.00 ][/FONT]
[FONT=&quot] 2. MOMO Sports Steering [ $ 770.00 ][/FONT]
[FONT=&quot] 3. MOMO Gear Knob [ $ 150.00 ][/FONT]
[FONT=&quot]----------------------------------------------------[/FONT]
[FONT=&quot]Enter name : Suhaimi Sarip[/FONT]
[FONT=&quot]Enter choice : 3[/FONT]
[FONT=&quot]Enter quantity : 1[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]----------------------------------------------------[/FONT]
[FONT=&quot]- RECEIPT OF PURCHASE -[/FONT]
[FONT=&quot]----------------------------------------------------[/FONT]
[FONT=&quot]Name : Suhaimi Sarip[/FONT]
[FONT=&quot]Item : MOMO Gear Knob[/FONT]
[FONT=&quot]Price : RM 150.00[/FONT]
[FONT=&quot]Quantity : 1[/FONT]
[FONT=&quot]Payment : RM 150.00[/FONT]
[FONT=&quot]----------------------------------------------------[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]Would you like to continue ? : n[/FONT]
[FONT=&quot] [/FONT]

[TABLE]
[TR]
[TD="width: 195, bgcolor: white"] [TABLE]
[TR]
[TD] If the user chooses not to continue, display the grand total and how many of each item has been sold.

[/TD]
[/TR]
[/TABLE]
[/TD]
[/TR]
[/TABLE]
[FONT=&quot]-------------------------------------------------[/FONT]

[FONT=&quot]- TODAY'S SUMMARY -[/FONT]
[FONT=&quot]-------------------------------------------------[/FONT]
[FONT=&quot]Total Payment : $ 3230.00[/FONT]
[FONT=&quot]Item 1 sold : 0[/FONT]

[FONT=&quot]Item 2 sold : 4[/FONT]
[FONT=&quot]Item 3 sold : 1[/FONT]
[FONT=&quot] [/FONT]
[/TD]
[/TR]
[/TABLE]











#include <stdio.h>

void menu();
char get_item(int choice);
float get_price(int choice);
void display(char,char,float,int,float);


int main()
{

int quantity =0, no_of_item = 0,choice;
float payment,item_price;
char contin [2], item_name[15], name[20];



menu();

printf("\n Enter your name:");
gets(name);
printf("\nEnter choice:");
scanf("%d",&choice);

printf("\nEnter quantity:");
scanf("%d",quantity);



item_name[15] = get_item(choice);
item_price = get_price(choice);
payment = item_price*quantity;

display (name[20],item_name[15],item_price,quantity,payment);


getche();
return 0;

}




void menu()
{

printf("\n------------------------------------");
printf("\n - Welcome to my car accesories - ");
printf("\n------------------------------------");
printf("\n1. Pioneer mp3 player [300.00] ");
printf("\n2. Momo sports steering [770.00]");
printf("\n3. Momo gear knob [150.00]");
printf("\n------------------------------------");

}

char get_item(int choice)
{

char item_name[15];
switch (choice)
{
case 1: strcpy (item_name, "Pioneer mp3 player");
break;

case 2: strcpy (item_name,"Momo sports steering");
break;

case 3: strcpy (item_name, "Momo gear knob");
break;

default : strcpy (item_name,"invalid");

}
{
return (item_name[15]);
}
}
float get_price(int choice)
{
float item_price;

switch (choice)
{
case 1: item_price = 300.00;
break;

case 2: item_price = 770.00;
break;

case 3: item_price = 150.00;
break;

default : item_price = 0;


}
{
return (item_price);
}
}
void display(char name, char item_name, float item_price, int quantity,float payment)

{
printf("\n--------------------------------------");
printf("\n - Receipt of purchase - ");
printf("\n--------------------------------------");
printf("\nName: %c",name);
printf("\nItem: %c",item_name);
printf("\nPrice:%.2f",item_price);
printf("\nQuantity:%d",quantity);
printf("\nPayment:%.2f",payment);
printf("\n--------------------------------------");

}

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform