A place for coders and developers to share, learn and grow together.
C++ | Using GoTo Statements
This is a program for simple goto statement in c++. The user inputs the gender and if it is incorrect the it goes to start. The program is extendable. Go enjoy the program. Lets begin…
Program for Goto Statements in C++.
//clear the screen.
//declare variable char.
//label for goto
//Input the two numbers save them
cout<<"Enter your gender"<<endl;
cout<<"You have got 10% discount";
cout<<"You have got 20% discount";
Output Enter your gender a Try again Enter your gender m You have got 10% discount.
How does it work. 1. You enter gender. 2. The switch statement decides the correct discount and if incorrect gender goes back to start.
Extending it. The program is extendable. This is a basic concept of c++ and can be used in any program. Go extend it..
Explanation. 1. Include ‘iostream.h’ and ‘conio.h’ and ‘fstream.h’ files. 2. Add void main. 3. Start program by first clearing the screen. 4. Declare variables. 5. Declare your label. 6. Add cout and cin to get data. 7. Add a switch statement. 8. Add a goto to label in default. 9. Get character.
At the end You learnt creating the C++ program for using goto statements. So now enjoy the program.
P.S. If you have any questions, click here to join our community and feel free to ask any questions.