C++ question about running the programm again
alright Im trying to make my programms run again after they have completed their task with "would you like to run the program again? y/n?" thing but I can''t figure out how to make it work. Your assistance is much appriciated
-----------------------------
Programming is confussing!
AIM: Trebor DoD
-----------------------------AIM: Trebor DoDHompage: Thinking Digitally: My Web Blog
January 09, 2003 08:06 PM
main()
{
do
{
cout << "Heya!" << endl;
char ans;
cout << "\nWould you like to run the program again?";
cin >> ans;
ans = toupper(ans);
}while(ans == ''Y'');
}
{
do
{
cout << "Heya!" << endl;
char ans;
cout << "\nWould you like to run the program again?";
cin >> ans;
ans = toupper(ans);
}while(ans == ''Y'');
}
AP your code didn''t even compile This is what I entered and it had 5 errors.
#include <iostream>
using namespace std;
main()
{
do
{
cout << "Heya!" << endl;
char ans;
cout << "\nWould you like to run the program again?";
cin >> ans;
ans = toupper(ans);
}
-----------------------------
Programming is confussing!
AIM: Trebor DoD
#include <iostream>
using namespace std;
main()
{
do
{
cout << "Heya!" << endl;
char ans;
cout << "\nWould you like to run the program again?";
cin >> ans;
ans = toupper(ans);
}
-----------------------------
Programming is confussing!
AIM: Trebor DoD
-----------------------------AIM: Trebor DoDHompage: Thinking Digitally: My Web Blog
#include <iostream>using namespace std;int main(){ char ans; do { cout << "Heya!" << endl; //char ans; // local to 'do' cout << "\nWould you like to run the program again?"; cin >> ans; ans = toupper(ans); } while(ans == 'Y'); return 0;}
[edited by - deal on January 9, 2003 9:54:40 PM]
ok thanks deal but now I am getting this error
12 implicit declaration of function `int toupper(...)''
what does that mean?
-----------------------------
Programming is confussing!
AIM: Trebor DoD
12 implicit declaration of function `int toupper(...)''
what does that mean?
-----------------------------
Programming is confussing!
AIM: Trebor DoD
-----------------------------AIM: Trebor DoDHompage: Thinking Digitally: My Web Blog
quote: Original post by Digigamer15
ok thanks deal but now I am getting this error
12 implicit declaration of function `int toupper(...)''
what does that mean?
-----------------------------
Programming is confussing!
AIM: Trebor DoD
u need to include another header file.. i think is ctype to use toupper :D
Metal Typhoon
alright thanks a lot Metal Typhoon.
I got the heya! program to run correctly now I just got to implement that code into the program I want to put it in and get it to work :-/
-----------------------------
Programming is confussing!
AIM: Trebor DoD
I got the heya! program to run correctly now I just got to implement that code into the program I want to put it in and get it to work :-/
-----------------------------
Programming is confussing!
AIM: Trebor DoD
-----------------------------AIM: Trebor DoDHompage: Thinking Digitally: My Web Blog
I know C++ Programmers like to avoid the goto command, but if you want the WHOLE process of your program to START over, just put Start: under int main() { and this whereever u want to ask the question:
char choice;
std::cout << "Would you like to run the program again? y/n ";
std::cin >> choice;
if( choice == ''Y'' || choice == ''y'' )
goto Start;
else
return 0;
the Do...While loop does the same exact thing though and its easier to understand the code with the Do...While loop. But I just wanted to show you another way.
char choice;
std::cout << "Would you like to run the program again? y/n ";
std::cin >> choice;
if( choice == ''Y'' || choice == ''y'' )
goto Start;
else
return 0;
the Do...While loop does the same exact thing though and its easier to understand the code with the Do...While loop. But I just wanted to show you another way.
You could also have the body of the program (the bit you want to repeat) in another function, and have the main() function call that function repeatedly. The advantage is that you can treat the second function as a program in it''s own right.
If you''re feeling classy, you could set up your program as a class:
The advantage of that approach - at least as you get more advanced - is that if your application needs to clean things up or reset things, it gets done by the constructor/destructor.
Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.
If you''re feeling classy, you could set up your program as a class:
class CApplication{ CApplication(){}; ~CApplication(){}; bool Run(); //this function is the ''body'' of your program again};void main(void){ CApplication *app=0; do { app = new CApplication(); app->Run(); delete app; }while(UserStillWantsToPlay())}
The advantage of that approach - at least as you get more advanced - is that if your application needs to clean things up or reset things, it gets done by the constructor/destructor.
Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.
Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement