cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Problem with loops
Problem with loops
Jul 22, 2012 at 2:09pm UTC
boobs
(3)
Hi im just learning cpp and have a problem with loops here is some example code
#include <iostream>
using namespace std;
int main()
{
int title;
loop:
cout << "Welcome to Text world" << endl;
cout << "Press 1 to start or 2 for help ";
cin >> title;
if
(title == 1)
cout << "loading..." << endl;
else if
(title == 2)
cout << "Help...." << endl;
else
cout << "Invalid selection, please try again...." << endl;
goto loop;
return 0;
}
The code works but if option 1 or 2 is chosen the program loops and thats no what I wan I just want it to loop with the eles statement not the others.
hope someone can help
Jul 22, 2012 at 2:13pm UTC
Peter87
(11234)
Nice to meet you(r) boobs. :)
You can use curly brackets  to have more than one statement in the else part.
1
2
3
4
5
6
...
else
{ cout <<
"Invalid selection, please try again...."
<< endl;
goto
loop; }
Jul 22, 2012 at 2:14pm UTC
boobs
(3)
Thanks peter thats a big help.....
Topic archived. No new replies allowed.