Jump to content
  • Advertisement
Sign in to follow this  
Xloner12

continue?

This topic is 4849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
#include <iostream>
#include <string>


using std::cin;
using std::cout;
using std::endl;
using std::string;


int main(void)
{
cout << "Difficulty levels\n\n";
cout << "1 - easy\n";
cout << "2 - Normal\n";
cout << "3 - hard\n\n";

int choice;
cout << "Choice: ";
cin >> choice;

switch(choice)
{
case 1: cout << "You picked Easy.\n";
break;

case 2: cout << "You picked normal.\n";
break;

case 3: cout << "You picked hard.\n";
break;

default: cout << "Invalid option, choose again.\n";
continue;

}
return 0;

I get an error on continues line. when i try to compile

Share this post


Link to post
Share on other sites
As far as I know, continue works fine in C++, and in the exact same way it does in C.

For example, this is a valid way to count from 1 to 10:


int k=0;
while (1) {
k++;
cout << k << " ";
if (k<10) continue;
break;
}



What compiler are you using?

Share this post


Link to post
Share on other sites
dev c++

its probly something like a comman or oh wait, do you need to declare like a std::continue or some other declartion like that.

Im problying going to feel stupid when i figure this one out :P

Share this post


Link to post
Share on other sites
Quote:
Original post by Xloner12
dev c++

its probly something like a comman or oh wait, do you need to declare like a std::continue or some other declartion like that.

Im problying going to feel stupid when i figure this one out :P


continue is a keyword, not part of the standard library. Read my previous post for more information.

Share this post


Link to post
Share on other sites
ahh, see I do feel stupid. I was using in a loop for that back in c. Then i try'ed it in a c++ statment now that im learning it. Bah. Thanks guys.

Share this post


Link to post
Share on other sites
#include <iostream>
#include <string>


using std::cin;
using std::cout;
using std::endl;
using std::string;


int main(void)
{
cout << "Difficulty levels\n\n";
cout << "1 - easy\n";
cout << "2 - Normal\n";
cout << "3 - hard\n\n";

int choice;
cout << "Choice: ";
cin >> choice;

switch(choice)
{
case 1: cout << "You picked Easy.\n";
break;

case 2: cout << "You picked normal.\n";
break;

case 3: cout << "You picked hard.\n";
break;

default: cout << "Invalid option, choose again.\n";
continue;

}
return 0;


Your use of continue in this example isn't consistent with the examples that others have shown. The difference is that they use continue in a loop; your usage here is both illegal and impractical. Continue simply tells the loop to continue to the next iteration. Since you aren't using a loop, continue won't do anything. The following might be what you're looking for :

#include <iostream>
#include <string>


using std::cin;
using std::cout;
using std::endl;
using std::string;


int main(void)
{

int choice;
bool done = false;
while( done != true)
{
cout << "Difficulty levels\n\n";
cout << "1 - easy\n";
cout << "2 - Normal\n";
cout << "3 - hard\n\n";

cin >> choice;

switch(choice)
{
case 1: cout << "You picked Easy.\n";
done = true;
break;

case 2: cout << "You picked normal.\n";
done = true;
break;

case 3: cout << "You picked hard.\n";
done = true;
break;

default: cout << "Invalid option, choose again.\n";
done = false;
continue; // proper usage

}
}
return 0;
}




<edit :: Far too slow [grin].

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!