# Thread: a program for a super market!

1. ## 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;

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("[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("How many?\n",x);
scanf("%d",&x);

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. 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. Originally Posted by Libpgeak
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. 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;
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("[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("How many?\n",x);
scanf("%d",&x);

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. how to show the total at the end.i donot know how to do it with while loop.please guide me.