+ 3

exit from boolean function

hello guyz. I have 1 problem here. I want to create boolean funqction witch asks u do u want to exit program or play again(I'm making a seample game) and while user press n(no) the program must exit. have any ideas?

28th Feb 2018, 9:34 PM
Dato Khojava
Dato Khojava - avatar
12 ответов
+ 8
Link the code you are having issue with here. on a new comment press [ + INSERT ] Then press [CODE] select the problem code
28th Feb 2018, 9:45 PM
Manual
Manual - avatar
+ 7
A few more lesson in the course will give you some of what you need. What are you using to make the game an engine? a library?
28th Feb 2018, 9:38 PM
Manual
Manual - avatar
+ 7
@John Wells is right use exit(0) or return 0; says your code is done.
28th Feb 2018, 9:57 PM
Manual
Manual - avatar
28th Feb 2018, 9:52 PM
John Wells
John Wells - avatar
+ 6
what software are you using? You need to use the close window code to exit your game. when the answer is n. that is all I can reccommend for you.
28th Feb 2018, 9:55 PM
Manual
Manual - avatar
+ 5
Or do you mean how to call a function when you win, lose, or draw?
28th Feb 2018, 9:51 PM
Manual
Manual - avatar
+ 3
Closing a game. depends on the game library or Engine being used. - not standard C++ you cannot do stuff like that on sololearn.
28th Feb 2018, 9:49 PM
Manual
Manual - avatar
+ 2
ok ty
28th Feb 2018, 9:56 PM
Dato Khojava
Dato Khojava - avatar
+ 1
I make it by myself with function and then upgreaded it with oop. Look at my codes. So u cant give me a hint how to exit the program ?
28th Feb 2018, 9:43 PM
Dato Khojava
Dato Khojava - avatar
+ 1
bool Replay(){ char answer; cout << "if u want play again press y else n "; cin >> answer; if( answer == 'n'){ // here i want while user press n the program must exit. } }
28th Feb 2018, 9:52 PM
Dato Khojava
Dato Khojava - avatar
+ 1
You can also use the “GetAsyncKeyState(‘n’)” function of the windows.h library.. like this: bool Replay(){ char answer; cout << "if u want play again press y else n "; cin >> answer; if( GetAsyncKeyState(‘n’)){ //break; || return 0 //whatever you want } This should work
28th Feb 2018, 10:16 PM
Chob
Chob - avatar
0
Write exit(0) after if stmt
1st Mar 2018, 12:10 AM
Sourav Sharma
Sourav Sharma - avatar