Thread: a program for a super market!

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    64

    a program for a super market!

    Suppose you have to develop a program for managing the sales of your grocery store. The following functions have been requested by your Head (The shopkeeper):
    1: The program should allow the user to select and buy different items present in that shop.
    2: The user should be able to see the items that he has bought and print his total bill on the screen
    3: The program should not end until the user specifies it to end. (The user should press 'q' to quit the program)
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    
    int main(){
    char choice;
    int x,sugar=350,jam=250,shampoo=199,bread=50 ,eggs=90,subtotal1=0,subtotal2=0,subtotal3=0,subtotal4=0,subtotal5=0,total;
    
    
    printf("WELCOME TO NUST DHABBA\n");
    printf("World's biggest Departmental store\n");
    printf("Enter choice\n");
    printf("[1] for 1 kg sugar bag\n");
    printf("[2] for Jam\n");
    printf("[3] for XYZ Shampoo\n");
    printf("[4] for Bread\n");
    printf("[5] for 1 dozen eggs\n");
    printf("[q] to quit shoping\n");
    choice=getch();
    
    if((choice=='q')||(choice=='Q'))
    exit(0);
    
    if(choice=='1') {
    printf("shopped:1 kg sugar bag=350 rupees\n",sugar);
    printf("how many?\n",x);
    scanf("%d",&x);
    subtotal1=sugar*x;
    printf("Sub total:sugar=%d",subtotal1);
    getche();
    }
    
    if(choice=='2'){
    printf("Shopped:Jam=250\n",jam);
    printf("How many?\n",x);
    scanf("%d",&x);
    subtotal2=jam*x;
    printf("Sub total:Jam=%d",subtotal2);
    getch();
    }
    if(choice=='3') {
    
    printf("shopped:XYZ shampoo\n",shampoo);
    printf("How many?\n",x);
    scanf("%d",&x);
    subtotal3=shampoo*x;
    printf("Sub total:shampoo=%d",subtotal3);
    getch();
    }
    
    if(choice=='4'){
    printf("Shopped:Bread\n",bread);
    printf("How many?\n",x);
    scanf("%d",&x);
    subtotal4=bread*x;
    printf("Sub total:Bread=%d",subtotal4);
    
    getch();
    }
    if(choice=='5') {
    
    printf("shopped:dozen eggs\n",shampoo);
    printf("How many dozens you want?\n",x);
    scanf("%d",&x);
    subtotal5=eggs*x;
    printf("Sub total:eggs=%d",subtotal5);
    getch();
    }}
    how can i print the total and how can the man (who came for shopping) buy other items too.in the above program the buyer cannot buy more than one thing why?

  2. #2
    Registered User
    Join Date
    Sep 2011
    Posts
    52
    Well, you're not in a loop. When your program is at the end of the line, he is just "done". Quick fix: make a function wich make up the bill. Place your code in a while loop. Ask the costummer if he want to buy more: Yes, stay in your loop. No: break the loop. Then make up the bill. Thats it

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    64
    Quote Originally Posted by Libpgeak View Post
    Well, you're not in a loop. When your program is at the end of the line, he is just "done". Quick fix: make a function wich make up the bill. Place your code in a while loop. Ask the costummer if he want to buy more: Yes, stay in your loop. No: break the loop. Then make up the bill. Thats it
    can you give me some idea? by doing some ammendment in the code!!!

  4. #4
    Registered User
    Join Date
    Sep 2011
    Posts
    52
    Ok, this is al made without a debugger, so there may be a few typo's. It's just to show you how to do it.

    Code:
    int main(){
    char choice;
    int x,sugar=350,jam=250,shampoo=199,bread=50 ,eggs=90,subtotal1=0,subtotal2=0,subtotal3=0,subtotal4=0,subtotal5=0,total;
     char shopping=1; 
    printf("WELCOME TO NUST DHABBA\n");
    printf("World's biggest Departmental store\n");
    
    while(shopping)
    {
    printf("Enter choice\n");
    printf("[1] for 1 kg sugar bag\n");
    printf("[2] for Jam\n");
    printf("[3] for XYZ Shampoo\n");
    printf("[4] for Bread\n");
    printf("[5] for 1 dozen eggs\n");
    printf("[q] to quit shoping\n");
    choice=getch();
     
    if((choice=='q')||(choice=='Q'))
    exit(0);
     
    if(choice=='1') {
    printf("shopped:1 kg sugar bag=350 rupees\n",sugar);
    printf("how many?\n",x);
    scanf("%d",&x);
    subtotal1=sugar*x;
    printf("Sub total:sugar=%d",subtotal1);
    getche();
    }
     
    if(choice=='2'){
    printf("Shopped:Jam=250\n",jam);
    printf("How many?\n",x);
    scanf("%d",&x);
    subtotal2=jam*x;
    printf("Sub total:Jam=%d",subtotal2);
    getch();
    }
    if(choice=='3') {
     
    printf("shopped:XYZ shampoo\n",shampoo);
    printf("How many?\n",x);
    scanf("%d",&x);
    subtotal3=shampoo*x;
    printf("Sub total:shampoo=%d",subtotal3);
    getch();
    }
     
    if(choice=='4'){
    printf("Shopped:Bread\n",bread);
    printf("How many?\n",x);
    scanf("%d",&x);
    subtotal4=bread*x;
    printf("Sub total:Bread=%d",subtotal4);
     
    getch();
    }
    if(choice=='5') {
     
    printf("shopped:dozen eggs\n",shampoo);
    printf("How many dozens you want?\n",x);
    scanf("%d",&x);
    subtotal5=eggs*x;
    printf("Sub total:eggs=%d",subtotal5);
    getch();
    }
    
    printf("Do you wish to continue shopping? Y / N");
    choice=getch(); 
    if((choice != 'Y')
    shopping=0;  //break the loop
    }
    //now we are done with shopping, so show is the subtotal enz
    //That part you can make up by yourself
    }

    I hope it is clear to you. If the costummer doesn't want to shop anymore, just break the loop. You can even do it a litle bit more fancy with a while(1) loop, and a break;. That way, you will spare 1 byte(and for assambly programmers like me, thats worth it)

    Let me hear it from you it if you got anymore questions left!

    Libpgeak

    p.s. work on your programming style, it's horrible...

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    64
    how to show the total at the end.i donot know how to do it with while loop.please guide me.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Reposted - market program please help
    Closed.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Market Needs
    By Smeagol in forum C++ Programming
    Replies: 14
    Last Post: 05-29-2006, 03:06 PM
  2. Items with a HOT market
    By holden in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 09-06-2004, 10:27 PM
  3. Super Easy C++ program help
    By ftblstr2319 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 05:07 PM
  4. Stock market
    By Liger86 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 05-20-2003, 05:12 PM
  5. stock market question
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 03-29-2003, 01:48 PM