I have also written a simple 'Hello User' C++ program (Identical to the 'Hello World' program apart from the cout text output.
How could I write this program to first ask the user to press the '1' keyboard key to see the 'Hello World' output, and the '2' keyboard key to see the 'Hello User' output?
in the above example, is it possible to define a cin variable that will accept a text word-command (such as 'help' or 'info') instead of just a single integer?
How would I do that?
Here's my (working) code. I want to replace the option for '5' and '6' with 'info' and 'exit'.
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <string>
usingnamespace std;
int main()
{
// holds the value of the user's input.
int num;
// arbitrary value of variable 'beans'.
int beans = 1000;
// arbitrary value of variable 'rice'.
int rice = 800;
List:
cout << "Press 1 to see the number of beans." << endl;
cout << "Press 2 to see the amount of rice." << endl;
cout << "Press 3 to see the Memory Address of the beans value" << endl;
cout << "Press 4 to see the Memory Address of the rice value." << endl;
cout << "Press 5 to see this list again." << endl;
cout << "Press 6 to end the program." << endl;
StartOver:
cin >> num;
if (num == 1)
{
cout << beans << endl;
goto StartOver;
}
if (num == 2)
{
cout << rice << endl;
goto StartOver;
}
if (num == 3)
{
cout << &beans << endl;
goto StartOver;
}
if (num == 4)
{
cout << &rice << endl;
goto StartOver;
}
if (num == 5)
{
goto List;
}
if (num == 6)
{
goto exit;
}
else
{
cout << "Your input was not on the list. Please try again." << endl;
goto StartOver;
}
exit:
return 0;
}