Hi I have only been working with c++ for a week now so hopefully I don't sound to ignorant. I have been trying to find a way to only allow an end user to enter a 1 or a 2 and if they don't then loop. Here is the direct code that I am trying to adjust to do this.
1 2 3 4 5 6 7 8 9 10 11 12 13
{
//GK stands for Gas Kind
string GK;
GK = "1";
cout << "Please type 1 for Leaded or 2 for Unleaded ";
//GC stands for Gas Choice
string GC;
getline(cin, GC);
cout << "You entered " << GC << " ";
system("PAUSE");
{
if (GK == GC)
{
If you know GC can only be 1 or 2, you might wanna define it as an integer since this requires less memory and is good practice. Unless ofcourse you're gonna use some string operations in the rest of your program on this GC variable.
actually this is the only time it gets used in the code, it merely tells the program which direction to take next. I haven't used integers yet though, what is the format for that instead of string?