Debugging Stub Functions

Okay, I am a newbie in C++, but I have done the reading, searched Google, and joined the MSDN developers; however, it seems that when you ask a simple
question in C++ forums, as in the case below, you don't get a response.

As far as I am concerned all the rules are being followed, I have this same code
in another function: void invmenu(), and it works; however, I have been sitting
here for 3 hours trying to figure out what is wrong with this section of my code.

For example, when I run this program repListing(); should display: "You are now
in report listing," which is not shown on the code listed below. But instead of
displaying "You are now in report listing." not shown below, it displays
"Inventory Listing"
Why?
void reports()
{

int choice = 0;
while (choice!=7)
{
choice++;
cout <<"\t\t\t Serendipity Booksellers"<< endl;
cout <<"\t\t\t\t Reports\n"<<endl;
cout <<" \t\t\t 1. Inventory Listing"<< endl;
cout <<" \t\t\t 2. Inventory Wholsale Value"<< endl;
cout <<" \t\t\t 3. Inventory Retail Value"<< endl;
cout <<" \t\t\t 4. Listing by Quantity"<< endl;
cout <<" \t\t\t 5. Listing by Cost"<< endl;
cout <<" \t\t\t 6. Listing by Age" << endl;
cout <<" \t\t\t 7. Return to the Main Menu\n\n"<< endl;
cout <<"\t\t\t Enter Your Choice: ";
cin >> choice;


}
switch (choice)
{
case 1: repListing();
break;
case 2: repWholsale();
break;
case 3: repRetail();
break;
case 4: repQty();
break;
case 5: repCost();
break;
case 6: repAge();
break;
case 7: cout << "\t\t\t\tYou entered 7.\n";
cout << "\t\t\t You did not enter 1,2,3,4,5,or 6.!\n";

}
}
1. The switch tests hould be part of the while loop.

2. case 7: should have a return statement.

3. choice++ is irrelevant ?
agree'd. that choice++ is not doing anything, since you are assinging a new number to choice when you get the cin >> anyway.

and, that while (choice != 7) means that the loop will never exit unless you choose 7. By which point, the switch has only one option it will display, and that's from case 7:.

You should either get rid of the while loop, or put the switch statement into the while loop, and add for case 7: a return statement to exit the switch block and the while loop at the same time.
Thank you Guestgulkan and Aakanaar for the quick response and the explanations that helped clear up my mind.

Trying to learn how to program in C++ solo, without the help of
others is difficult if not impossible.

The folks at MSDN are helpful to some extent, but for some weird reason they keep embedding url links that reference cplusplus; in addition,to sometimes not responding to thread questions.

So i figured instead of wasting my time with MSDN, and no support for
C++ on Linux, I will just join
cplus plus.

Thank you again, you guys totally rock!

Now I can focus on Arrays.


Topic archived. No new replies allowed.