+ 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?
12 Réponses
+ 8
Link the code you are having issue with here.
on a new comment press
[ + INSERT ]
Then press
[CODE]
select the problem code
+ 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?
+ 7
@John Wells is right use exit(0) or return 0;
says your code is done.
+ 6
+ 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.
+ 5
Or do you mean how to call a function when you win, lose, or draw?
+ 3
Closing a game.
depends on the game library or Engine being used.
- not standard C++
you cannot do stuff like that on sololearn.
+ 2
ok ty
+ 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 ?
+ 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.
}
}
+ 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
0
Write exit(0) after if stmt