CrazyEngineers
  • [FONT=&]1. [/FONT]Write a complete program based on the following requirements:
    · In the main( ) function :
    [FONT=&]o [/FONT]Ask the user whether they want to continue executing the program.
    [FONT=&]o [/FONT]
    [FONT=&]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=&]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=&]o [/FONT]Display the menu as shown in the output screen.

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

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

    · In function display(…) :
    [FONT=&]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="] [/FONT]

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

    [FONT="] [/FONT]
    [FONT="]----------------------------------------------------[/FONT]

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

    [/TD]
    [/TR]
    [/TABLE]
    [/TD]
    [/TR]
    [/TABLE]
    [FONT="]- WELCOME TO MYCAR ACCESORIES -[/FONT]
    [FONT="]----------------------------------------------------[/FONT]
    [FONT="] 1. Pioneer MP3 Player [ $ 350.00 ][/FONT]
    [FONT="] 2. MOMO Sports Steering [ $ 770.00 ][/FONT]
    [FONT="] 3. MOMO Gear Knob [ $ 150.00 ][/FONT]
    [FONT="]----------------------------------------------------[/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="]Enter name : Usha Vellappan[/FONT]

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

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

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

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











    #include

    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--------------------------------------");

    }
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Home Channels Search Login Register