Hi
Im new to programing and am not taking a course or any thing just using this site so I would be very great full if someone would tell me if this example is the best syntax for this situation
#include <iostream>
#include <string>
using namespace std;
int main()
{
int x = 1;
string y;
while (x == 1)
{
{ cout << "hello press start to play q to quit" << endl;
loop:
getline (cin, y);}
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int x = 1;
string y;
while (x == 1)
{
{
cout << "hello press start to play q to quit" << endl;
loop:
getline (cin, y);}
if (y == "s")
{
x = x + 1;
}
elseif (y == "q" )
{
x = x+2;
}
else
{
cout << "Invalid input" << endl;
goto loop;
}
}
while (x == 2)
{
cout << "starting..." << endl;
return 0;
}
while (x == 3)
{
cout << "goodbye..." << endl;
return 0;
}
}
As you can see, it is MUCH easier to read, and you can clearly see that you are missing the closing brace for main. Also, I am curious why you used a nameless scope on line 12?
Nameless scopes are not commonly used. The only use I've seen them in is when a block of code only needs to be used once, the variable declarations are used once, and when it pulls data from variables outside of the scope. (a function is normally used for this, but there are exceptions)
@strongdrink: I use nameless scopes when I need unconditional code to execute with temporary stack variables. Since he is not making any temporary stack variables it seems odd :\ unless he just wanted to keep the "loop" label in its own scope?