viewing paste Unknown #13505 | C++

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
/*
Simple Menu with 3 options.
1) Input string
2) Print string
3) Exit
*/
 
 
#include <iostream>
#include <string>
using namespace std;
 
 
int main()
{
    //User is finished and while loop ends if variable running is not 1.
    int running = 1;
    string f = "";
 
    while (running == 1)
    {
        cout << "Please enter either 1, 2, or 3 \n 1.) Type a sentence. \n 2.) Check last sentence typed. \n 3.) Exit Program.\n";
        int input = 0;
        cin >> input;
        switch (input)
        {
            case 1: //Inputs user string and stores it.
                cout << "Type whatever you want. \n";
                cin >> f;
                cout << "The sentence has been saved." << "\n";
                break;
 
            case 2: //Display last sentence from case 1
                if (f == "" | f ==" ")
                {
                    cout << "Nothing was last typed. \n";
                    break;
                }
                else
                {
                    cout << "The last string entered was...\n" << f << "\n";
                    break;
                }
            case 3: //Exit
                cout << "Exiting the program\n";
                running = 0;
                break;
 
        }
    }
    //out of the loop
    cout << "This is out of the loop.";
    cin.get();
    cin.get();
}
Viewed 664 times, submitted by Guest.