After completing if statement, return to top of Main?

Hello, currently I am working on a program that has a variety of choices that a user can choose from, simply by entering letters A through F, which then sends them to the appropriate if statement. After completing the if statement that they request, is there a way to prompt them for another value and keep them in the loop until they enter a different value? To me it seems like a while loop but I cant seem to get it to work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  cout << endl << endl << "Enter letter of choice: ";
	cin >> userChoice;

if (userChoice == 'D') {
		int counter = 0;
		double totalInventoryPrice = 0;
		while (inventory[counter].amount > 0) { //while amount not less than zero fix this
			cout << left;
			cout << setw(15) << inventory[counter].name << setw(15) << inventory[counter].amount << setw(15) << inventory[counter].price << endl;
			totalInventoryPrice = totalInventoryPrice + (inventory[counter].price * inventory[counter].amount);
			counter++;
		}
		cout << endl << "Total inventory: " << totalInventoryPrice << endl << endl;
		cout << "Enter letter of choice: "; //my attempt to stay in the if statement
		cin >> userChoice;
	


Should be noted that there are more options below, varying from A-F.
closed account (SECMoG1T)
similar to this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

int main()
{
    char choice(' ');

    while(choice != 'x' && choice!='X')
    {
        ///your code here
        std::cout<<"Press any key to continue or x to quit: ";
        std::cin>>choice;
    }

    std::cout<<"good bye....";
}


you can use any option to quit the loop
Last edited on
Topic archived. No new replies allowed.