You are viewing our Forum Archives. To view or take place in current topics click here.
C++ Terminating to quickly
Posted:
C++ Terminating to quicklyPosted:
Status: Offline
Joined: Dec 30, 201211Year Member
Posts: 3,778
Reputation Power: 3016
Status: Offline
Joined: Dec 30, 201211Year Member
Posts: 3,778
Reputation Power: 3016
So lets say I build a simple program.
It always blows right past the code simply showing it for milliseconds and then it closes the application. I need to know a simple code that will allow the user to press "Q" to quit the program. I have been looking and looking but I have not found it.
I have never made an actual C++ program before so bare with me.
Thanks guys!
#include <iostream>
using namespace std;
int main()
{
string name;
cout << "Please enter your name!" << endl;
cin >> name;
cout << "Thank you for inputting your name. We will help you shortly." << endl;
return 0;
}
It always blows right past the code simply showing it for milliseconds and then it closes the application. I need to know a simple code that will allow the user to press "Q" to quit the program. I have been looking and looking but I have not found it.
I have never made an actual C++ program before so bare with me.
Thanks guys!
#2. Posted:
Status: Offline
Joined: Aug 16, 201212Year Member
Posts: 598
Reputation Power: 29
char x = cin.getch();
if(x == 'q')
return 0;
Sorry for previous answer.
Last edited by 7en ; edited 2 times in total
- 2useful
- 1not useful
#3. Posted:
Status: Offline
Joined: Aug 31, 201212Year Member
Posts: 1,553
Reputation Power: 65
Status: Offline
Joined: Aug 31, 201212Year Member
Posts: 1,553
Reputation Power: 65
You need to have some form of user input at the end of the program, or else it will do just that. That way, the user can press a key and it will finish running the program.
- 1useful
- 0not useful
#4. Posted:
Status: Offline
Joined: Dec 30, 201211Year Member
Posts: 3,778
Reputation Power: 3016
Abbreviate wroteThank you sir. +Rep for you!
char x = cin.getch();
if(x == 'q')
return 0;
Sorry for previous answer.
- 0useful
- 0not useful
#5. Posted:
Status: Offline
Joined: Dec 30, 201211Year Member
Posts: 3,778
Reputation Power: 3016
Status: Offline
Joined: Dec 30, 201211Year Member
Posts: 3,778
Reputation Power: 3016
Decisively wroteThanks man! I have a lot of great ideas coming up for my geometry class. Maybe a little cheating program? This is going to be fun!Abbreviate wrote
char x = cin.getch();
if(x == 'q')
return 0;
Sorry for previous answer.
That's what you need AWL! I programme.
It's difficult at first, but as soon as you
put years of practise into it, you won't need our help.
Good luck on your programme, have a brilliant day!
- 1useful
- 0not useful
#6. Posted:
Status: Offline
Joined: Apr 10, 201014Year Member
Posts: 124
Reputation Power: 4
#include <iostream>
#include <string>
int main()
{
string a;
getInput(cin, a); // places input in a
cout << a;
return 0;
}
- 0useful
- 1not useful
You are viewing our Forum Archives. To view or take place in current topics click here.