how to add variables in C++

so if you run this code you will be presented with a few options and select one and then another and another and so on after you pick 4 the total calories are suppossed to show up so how do i finish this code

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
int sum=0, choice;

printf("Option 1 CheeseBurger\n");

printf("Option 2 FishBurger\n");

printf("Option 3 VeggieBurger\n");

printf("Option 4 NoBurger\n");

scanf("%d" ,&choice);

if(choice==1) {printf("cheeseburger\n");sum=sum+461;}

if(choice==2) {printf("fishburger\n");sum=sum+431;}

if(choice==3) {printf ("veggieburger\n");sum=sum+420;}

if(choice==4) {printf ("no burger\n");sum=sum+0;}



printf("Option 5 Soft Drink\n");

printf("Option 6 Orange Juice\n");

printf("Option 7 Milk\n");

printf("Option 8 No Drink\n");

scanf("%d" ,&choice);

if(choice==1) {printf("Soft Drink\n");sum=sum+130;}

if(choice==2) {printf("Orange Juice\n");sum=sum+160;}

if(choice==3) {printf ("Milk\n");sum=sum+118;}

if(choice==4) {printf ("no Drink\n");sum=sum+0;}



printf("Option 9 Fries\n");

printf("Option 10 Baked Potato\n");

printf("Option 11 Chef Salad\n");

printf("Option 12 No Side\n");

scanf("%d" ,&choice);

if(choice==1) {printf("Fries\n");sum=sum+100;}

if(choice==2) {printf("Baked Potato\n");sum=sum+57;}

if(choice==3) {printf ("Chef salad\n");sum=sum+70;}

if(choice==4) {printf ("no Side\n");sum=sum+0;}



printf("Option 13 Apple Pie\n");

printf("Option 14 Sundae\n");

printf("Option 15 Fruit Cup\n");

printf("Option 16 No Dessert\n");

scanf("%d" ,&choice);

if(choice==1) {printf("Apple Pie\n");sum=sum+167;}

if(choice==2) {printf("Sundae\n");sum=sum+266;}

if(choice==3) {printf ("Fruit Cup\n");sum=sum+75;}

if(choice==4) {printf ("No Dessert\n");sum=sum+0;}



system("PAUSE");
return 0;
}
closed account (zwA4jE8b)
just output your text and the value of 'sum'. You all ready know how to output text, so just do that as well as output 'sum'
i figured it out thanks if you would like to try it oput and give me feedback thatd be great keep in mind this is my 3rd day ever programming in C


#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
int sum=0, choice;

printf("Welcome to Chippy's Chip Emporium\n");

printf("\nPlease select one item from each menu\n");

printf("\nOption 1 CheeseBurger\n");

printf("Option 2 FishBurger\n");

printf("Option 3 VeggieBurger\n");

printf("Option 4 NoBurger\n");

scanf("%d" ,&choice);

if(choice==1) {printf("cheeseburger\n");sum=sum+461;}

if(choice==2) {printf("fishburger\n");sum=sum+431;}

if(choice==3) {printf ("veggieburger\n");sum=sum+420;}

if(choice==4) {printf ("no burger\n");sum=sum+0;}



printf("Option 5 Soft Drink\n");

printf("Option 6 Orange Juice\n");

printf("Option 7 Milk\n");

printf("Option 8 No Drink\n");

scanf("%d" ,&choice);

if(choice==5) {printf("Soft Drink\n");sum=sum+130;}

if(choice==6) {printf("Orange Juice\n");sum=sum+160;}

if(choice==7) {printf ("Milk\n");sum=sum+118;}

if(choice==8) {printf ("no Drink\n");sum=sum+0;}



printf("Option 9 Fries\n");

printf("Option 10 Baked Potato\n");

printf("Option 11 Chef Salad\n");

printf("Option 12 No Side\n");

scanf("%d" ,&choice);

if(choice==9) {printf("Fries\n");sum=sum+100;}

if(choice==10) {printf("Baked Potato\n");sum=sum+57;}

if(choice==11) {printf ("Chef salad\n");sum=sum+70;}

if(choice==12) {printf ("no Side\n");sum=sum+0;}



printf("Option 13 Apple Pie\n");

printf("Option 14 Sundae\n");

printf("Option 15 Fruit Cup\n");

printf("Option 16 No Dessert\n");

scanf("%d" ,&choice);

if(choice==13) {printf("Apple Pie\n");sum=sum+167;}

if(choice==14) {printf("Sundae\n");sum=sum+266;}

if(choice==15) {printf ("Fruit Cup\n");sum=sum+75;}

if(choice==16) {printf ("No Dessert\n");sum=sum+0;}

printf("%d" , sum);

system("PAUSE");
return 0;
}
Not to be rude, but when posting code try and use the code format. It makes it a lot easier to read.
Try using STL and reduce the number of logical operators.

Try something like

1
2
3
4
5
6
7
8
9
10
11
12
for( int = 0 ; i < 3; ++i){
  string choice;
  cin >> choice;
  if(choice == 1){
      //Do stuff
  }else if(choice == 2) {
     //Do some other stuff
  }
  .
  .
  .
}
Last edited on
Topic archived. No new replies allowed.