Please Help. Completely Stuck Right Now!

I have a project for school where we have to create a menu for the user, then have the user select their item and loop the menu until the user types a certain character to exit the menu. Once they exit the menu, I need the program to print out what they ordered and how much their total is. I have everything working right except i cant figure out how to count the items they have ordered and print out their items at the end. Here is the code i have so far. Thank you for any help.

#include<stdlib.h>
#include<stdio.h>
#define PIZZA_SLICE 2.00
#define WHOLE_PIZZA 10.00
#define PIZZA_STICKS 3.50
#define SOFT_DRINK 1.50
#define CALZONE 4.75
#define SPAGHETTI_AND_MEATBALLS 6.95

main(){
int choice = 0, pizzaSliceCount = 0, totalOrder;
double totalPrice = 0;
printf("Welcome to Chef Chris' Pizzeria. May I take your order?\n");
do{
printf("Please make your selection\n");
printf("1. Pizza Slice %.2lf\n", PIZZA_SLICE);
printf("2. Whole Pizza %.2lf\n", WHOLE_PIZZA);
printf("3. Pizza Sticks %.2lf\n", PIZZA_STICKS);
printf("4. Calzone %.2lf\n", CALZONE);
printf("5. Spaghetti and Meatballs %.2lf\n", SPAGHETTI_AND_MEATBALLS);
printf("6. Soft Drink %.2lf\n", SOFT_DRINK);
printf("7. Exit\n");
scanf("%i", &choice);

switch(choice){
case 1:
totalPrice+=PIZZA_SLICE;
break;
case 2:
totalPrice+=WHOLE_PIZZA;
break;
case 3:
totalPrice+=PIZZA_STICKS;
break;
case 4:
totalPrice+=CALZONE;
break;
case 5:
totalPrice+=SPAGHETTI_AND_MEATBALLS;
break;
case 6:
totalPrice+=SOFT_DRINK;
break;
case 7:
break;
default:
printf("This is not a menu item\n");
}

printf("\nYour total so far is %.2lf\n", totalPrice);

} while(choice!=7);

printf("\nThats %i\n",pizzaSliceCount);
printf("\nYour total is %.2lf\n", totalPrice);

system("pause");
}
Last edited on
I suggest to create two arrays: one for menu items and other for items that were orderd.

For example,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
enum Item { PIZZA_SLICE, WHOLE_PIZZA,  PIZZA_STICKS, SOFT_DRINK,
                    CALZONE, SPAGHETTI_AND_MEATBALLS, TOTALl_ITEMS };
double menu_prices[ TOTAL_ITEMS ] = { 2.00, 10.00, 3.50, 1.50, 4.75, 6.95 };
double orders[ TOTAL_ITEMS ] = {};
...
...
 Item choice = TOTAL_ITEMS;
...

switch( choice )
{
    case PIZZA_SLICE + 1:
    totalPrice+=PIZZA_SLICE;
    orders[ PIZZA_SLICE ] ++;
    break;
...
... 
}
 
Last edited on
The only problem is I cant use arrays because we havent learned them yet. Im taking a intro to programming class and i can only use what we have learned. I know i need to make seperate count variables for each menu item. I just dont know where to put the count in the loop and also how to output the final count of items at the end of the program.

The program output should look like this(different menu items)


I take your order please?

Menu:
1. Hamburger $1.25
2. Cheeseburger $1.35
3. Fries $.95
4. Soda $.65
5. Ice cream Sundae $.75

6. Done with this order.

Enter Item: 2

Total so far: $1.35


Menu:
1. Hamburger $1.25
2. Cheeseburger $1.35
3. Fries $.95
4. Soda $.65
5. Ice cream Sundae $.75

6. Done with this order.

Enter Item: 4

Total so far: $2.00


Menu:
1. Hamburger $1.25
2. Cheeseburger $1.35
3. Fries $.95
4. Soda $.65
5. Ice cream Sundae $.75

6. Done with this order.

Enter Item: 8

*** Error: This is not on the menu.

Total so far: $2.00


Menu:
1. Hamburger $1.25
2. Cheeseburger $1.35
3. Fries $.95
4. Soda $.65
5. Ice cream Sundae $.75

6. Done with this order.

Enter Item: 6

That’s: 1 Cheeseburger
1 Soda
Your total is: $2.00
Topic archived. No new replies allowed.