jeudi 5 octobre 2017

How to make a a program loop forever until certain casein a switch statement is met?

How can I make this program loop forever unless the user chooses 'C' in the switch statement? I've tried several things on my own that didn't seem to work and I am not sure how to proceed, since I am still sort of a beginner in C++. Can anyone help? Let me know if you need additional info.

#include <iostream>
using namespace std;

int main()
{
    cout << "Hello user, what do you want to do: " << endl
        << "A. Display A Message" << endl
        << "B. Perform A Calculation" << endl
        << "C. Exit The Program" << endl;
    int result = 80 + 10;
    char answer;
    cin >> answer;
    switch (answer)
    {

    case 'A':
        cout << "Welcome to C++!" << endl;
        break;

    case 'B':
        cout << 80 << " + " << 10 << " = " << result << endl;
        break;

    case 'C':
        cout << "Goodbye...." << endl;
        break;
        return 0;
    }

}

Aucun commentaire:

Enregistrer un commentaire