help me how to repeat program

Jan 15, 2012 at 10:14am
cout << " Enter first number : " << endl;
cin >> a;

cout << " enter the operation " << endl;
cin >> ope;

cout << " enter the second number " << endl;
cin >> b;

switch(ope) {
case '+' : c = a + b;
break;
case '-' : c = a - b;
break;
case '*' : c = a * b;
break;
case '/' : c = a / b;
break;
}
cout << " Result is : " << c << endl;

If someone can tell me how to repeat this program,and how to clear screen after every result ?
Jan 15, 2012 at 11:23am
closed account (10oTURfi)
To repeat program, put everything in while(true){} loop.

To clear the screen http://cplusplus.com/articles/4z18T05o/
Jan 16, 2012 at 8:42am
To repeat, use Krofna's advice.

To clear the screen, use:
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;

There are also OS-specific methods of clearing the screen. Since you are posting on the Window's forum you can try:
system("cls")

However this is not a very safe method and I'll probably get yelled at for teaching it to you.
Jan 16, 2012 at 9:38am
If I use <conio.h> and <curses.h>,are thez good methds _ ?
Jan 16, 2012 at 10:25am
I don't have <curses.h> and don't really know what it is. But what exactly are you using from these libraries?

If you are doing something like:
printf("\n\n\n\n\n\n\n\n\n\n\n\n"); this would be essentially the same as the cout code I gave above.
Jan 16, 2012 at 11:40am
To repeat this program code - you can also use the goto statement.....
Jan 16, 2012 at 12:23pm
Noooooooooooooooooooooooooooooooooooooooo

The goto statement can very quickly cause unreadable and un-debuggable spaghetti code. It should be avoided whenever possible which is pretty much always. The goto command is left-over from older languages before structured programming was created. It is really only used for fool-proof and immediate exits from very deeply nested loops.

It is MUCH better to just put you entire code in a large while(true) or for(;;) statement.
Topic archived. No new replies allowed.