if statement with break!

game (22)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
char step;
 std::cout"Enter y for yes, n for n, proceed for p"<<endl;
 std::cin>>step;

if (step=='y')
{
   std::cout <<"YES"<<endl;
}
else if (step=='n')
{
std::cout <<"NO"<<endl;
}
else if (step=='p')
{
std::cout <<"PROCEED"<<endl;
}
else
{
//cin.clear();
//std::cout<<"You entered wrong character please try again;
//cin>>step;
break;
}



It doesn't work for me, what is the problem, any help!




The above code doesn't work,
Peter87 (3917)
You need << after cout on line 2.

break; is only used to break out of loops or switch statements. If your code is not inside a loop or a switch it doesn't make sense to use break;.
vlad from moscow (3662)
The break statement can be used only in an iteration statement (loop) or a switch statement. I see neither of these in your code.
game (22)
Okey thank your very much guys, It helps a lot.

Great!
Registered users can post here. Sign in or register to post.