Build not updating or run-time error?

I am a very beginner C++ programmer working on my first big program. It is a menu program/calorie counter hybrid, and i added in the calorie counter when all things went to hell.

The build solution says it's up-to-date, and when i rebuilt it it was okay, but the calorie counter does not seem to be working. Here is the program in its entirety, skip to the bottom to see my main problem. This is just in case the error is buried in my code.
#include <iostream>
#include <string>
using namespace std;
void breakfastMenu();
void baconAndEggs();
void cereal();
void pancakes();
void lunchMenu();
void PBandJ();
void cheeseburger();
void hotWings();
void dinnerMenu();
void salad();
void steak();
void fish();
void dessertMenu();
void chocolateCake();
void cobbler();
void applePie();
void iceCream();
bool finalOption(std::string);
int calories=0;
float cost=0;
int main()
{
bool exit=true;
cout<<"How many meals would you like?\n";
int j,i,k;
cin>>i;
for (k=0;k<i;k++)
{
cout<<"Which Meal?\n"<<"\t(1)Breakfast\n";
cout<<"\t(2)Lunch\n"<<"\t(3)Dinner\n";
cout<<"\t(4)Desert\n"<<"\t(0)Exit";
cin>>j;
switch (j)
{
case (1):
breakfastMenu();
break;
case (2):
lunchMenu();
break;
case (3):
dinnerMenu();
break;
case (4):
dessertMenu();
break;
case (0):
k=i; //breaks while loop
break;
default:
cout<<"That is not a valid option.";
k--;
break;
};
};
cout<<"Total Calories="<<calories<<"\n";
cout<<"Total Cost="<<cost<<"\n";
}

void breakfastMenu()
{
bool exit=true;
int i;
cout<<"Which meal would you like to have?\n"<<"\t(1)Cereal\n";
cout<<"\t(2)Bacon and Eggs\n"<<"\t(3)Pancakes\n";
cout<<"\t(0)Exit";
cin>>i;
switch (i)
{
case (1):
cereal();
break;
case (2):
baconAndEggs();
break;
case (3):
pancakes();
break;
case (0): //exits while loop
break;
default:
cout<<"That is not a valid option.\n";
break;
};
}

void cereal()
{
cout<<"Cereal is 90 calories\n"<<"Cereal costs $3.00\n";
if (finalOption("cereal"))
{
calories=calories+90;
cost=cost+3.00;
}
}
void baconAndEggs()
{
cout<<"Bacon and Eggs are 200 calories\n"<<"Bacon and Eggs cost $7.00\n";
if (finalOption("Bacon and Eggs"))
{
calories=calories+200;
cost=cost+7.00;
}
}
void pancakes()
{
cout<<"Pancakes are 350 calories\n"<<"Pancakes cost $5.00\n";
if(finalOption("Pancakes"))
{
calories=calories+350;
cost=cost+5.00;
}
}
void lunchMenu()
{
bool exit=true;
int i;
cout<<"Which meal would you like to have?\n";
cout<<"\t(1)Peanut Butter and Jelly\n"<<"\t(2)Cheeseburger\n";
cout<<"\t(3)Hot Wings\n"<<"\t(0)Exit\n";
cin>>i;
switch (i)
{
case (1):
PBandJ();
break;
case (2):
cheeseburger();
break;
case (3):
hotWings();
break;
case (0):
exit=false;
break;
default:
cout<<"That is not a valid option. Please choose again";
k--;
break;
};
}
void PBandJ()
{
cout<<"Peanut Butter and Jelly is 250 calories\n";
cout<<"Peanut Butter and Jelly costs $3.50\n";
if(finalOption("Peanut Butter and Jelly"))
{
calories=calories+250;
cost=cost+3.50;
}
}
void cheeseburger()
{
cout<<"A cheeseburger is 450 calories\n";
cout<<"A cheeseburger is 8.50\n";
if(finalOption("a cheeseburger"))
{
cost=cost+8.50;
calories=calories+450;
}
}
void hotWings()
{
cout<<"Hot Wings are 300 calories\n";
cout<<"Hot Wings cost $5.00\n";
if(finalOption("Hot Wings"))
{
cost=cost+5.00;
calories=calories+300;
}
}

void dinnerMenu()
{
bool exit=false;
int i;
cout<<"Which meal would you like?\n"<<"\t(1)Cheeseburger\n";
cout<<"\t(2)Salad\n"<<"\t(3)Steak\n";
cout<<"\t(4)Fish\n"<<"\t(0)Exit\n";
cin>>i;
switch (i)
{
case (1):
cheeseburger();
break;
case (2):
salad();
break;
case (3):
steak();
break;
case (4):
fish();
break;
case (0):
exit=false;
break;
default:
cout<<"That is not a viable option";
break;
};
}
void salad()
{
cout<<"A salad has 850 calories\n";
cout<<"A salad costs $6.50\n";
if(finalOption("a salad"))
{
calories=calories+850;
cost=cost+6.50;
}
void steak()
{
cout<<"A steak has 450 calories\n";
cout<<"A steak costs $10.00\n";
if(finalOption("a steak"))
{
cost=cost+10.00;
calories=calories+450;
}
}
void fish()
{
cout<<"Fish has 350 calories\n";
cout<<"Fish costs $6.50\n";
if(finalOption("fish"))
{
cost=cost+6.50;
calories=calories+350;
}

void dessertMenu()
{
int i;
cout<<"Which dessert would you like?\n"<<"\t(1)Chocolate Cake\n";
cout<<"\t(2)Cobbler\n"<<"\t(3)Apple Pie\n";
cout<<"\t(4)Ice Cream\n"<<"\t(0)Exit\n";
cin>>i;
switch (i)
{
case (1):
chocolateCake();
break;
case (2):
cobbler();
break;
case (3):
applePie();
break;
case (4):
iceCream();
break;
case (0):
break;
default:
cout<<"That is not a viable option\n";
break;
};
}
void chocolateCake()
{
cout<<"A chocolate cake has 550 calories\n";
cout<<"A chocolate cake costs $4.50\n";
if(finalOption("a chocolate cake"))
{
cost=cost+4.00;
calories=calories+550;
}
}
void cobbler()
{
cout<<"Today's cobbler is peach\n";
cout<<"Cobbler has 450 calories\n";
cout<<"Cobbler costs $6.50\n";
if(finalOption("cobbler"))
{
cost=cost+6.50;
calories=calroies+450;
}
}
void applePie()
{
cout<<"Apple pie has 350 calories\n";
cout<<"Apple pie costs $4.50\n";
if(finalOption("apple pie"))
{
calories=calories+350;
cost=cost+4.50;
}
void iceCream()
{
cout<<"Ice cream has 400 calories\n";
cout<<"Ice cream costs $3.50\n";
if(finalOption("ice cream"))
{
calories=calories+400;
cost=cost+3.50;
}
}
bool finalOption(string thatFood)
{
cout<<"Are you sure you would like "<<thatFood<<"?\n";
cout<<"(1)Yes\n"<<"(2)No\n";
int i;
cin>>i;
switch(i)
{
case (1):
cout<<"Your "<<thatFood<<" has been ordered\n";
return true;
break;
case (2):
cout<<"Your order for "<<thatFood<<" has been canceled\n";
return false;
break;
default:
return false;
break;
};
}

And when i finish selection, it does not display the calorie count or cost, which if i know anything should come up in a compiler time error (cause i'm probably doing it wrong), or show incorrect data due to my cout at the end of the main program.

I'm using Visual C++ Express, and it has been working fine up until now. I'm using global variable for my calorie count. I also can't get the spacing down on this forum, for some reason my tabs aren't working, so i apologize for the wall of text.

Any help?

Edit: I didn't realize how annoying that code wall is, so here is my primary problem:

I added these two lines:

cout<<"Total Calories="<<calories<<"\n";
cout<<"Total Cost="<<cost<<"\n";

At the end of the main program and it did nothing, not even display "Total Calories=". The code acted as if those two lines weren't even there.
Last edited on
Is it hard to understand my problem or do you guys just have no idea what's wrong?
Here's the thing. You're not supposed to have semi-colons after switch or for blocks.

-Albatross
I removed all semicolons after brackets, but it didn't change anything. Program still ran as if the lines weren't even there.
Does anyone have any idea?
Your code does not compile -have you posted the latest version?
Divide and conquer, my friend. Use comments and attempt to isolate the problem. If I had to guess, the lines are not being reached--so trace the path of execution and beware of infinite loops.
Thanks guys, but i have identified it as a definite compiler error.

I commented out my entire code, and it still works as it used to. I'm gonna save the code on word and reinstall Miscrosoft Visual C++, which is going to be a pain.

Thanks for the help!
Topic archived. No new replies allowed.