#include <iostream>
usingnamespace std;
int main()
{
int drinks;
cout<<"Hello to the virtual Beverage Machine."<<endl;
cout<<"Please choose your prefered beverage.\n";
cout<<"1. Pepsi"<<endl;
cout<<"2. 7Up"<<endl;
cout<<"3. Uva"<<endl;
cout<<"4. CocaCola"<<endl;
cout<<"5. Bison"<<endl;
cout<<":: ";
cin>>drinks;
cin.ignore();
switch (drinks) {
case 1:
cout<<"You have chosen Pepsi";
break;
case 2:
cout<<"You have chosen 7Up";
break;
case 3:
cout<<"You have chosen CocaCola";
break;
case 4:
cout<<"You have chosen RedBull";
break;
case 5:
cout<<"You have chosen Bison";
break;
default:
cout<<"You have chosen an invalid beverage.\n";
cout<<"Please, press enter to choose again.\n";
continue;
}
cin.get();
return 0;
}
So the thing is, why am I getting the (Continue statement not within a loop.) error?
and if it is possible, how can i assign the (You have chosen) into a variable? because whenever I type in: char chosen [25]= You have chosen
it always gets the (You) only..
continue stops the current iteration of the loop and goes straight to the next iteration, what exactly were you trying to accomplish with your continue statement?
Like I said, continue quits the current iteration of a loop, so if a continue statement is before the functionality of the loop it won't do anything for that iteration. See below:
1 2 3 4 5 6 7
for (int i=1; i<=5; i++)
{
if ( i == 3 )
continue;
std::cout << i << "\n";
}