I have a void that needs to end a program but a break and return 0 both won't work. Instead I have it cout (1/0). It works but is there an alternative?
#include <iostream>
#include <thread>
#include <Windows.h>
#include <limits>
usingnamespace std;
double clicks=0;
double result;
bool gameon=false;
char inpot;
bool wait=false;
void keyget(){
for(;;){
if ( GetAsyncKeyState ( VK_LBUTTON ) & SHRT_MAX && gameon==true){
clicks++;
}
else{
}
}
}
void other(){
for(;;){
cout <<"Starting game in 5..."<<endl;
Sleep(999);
cout <<"Starting game in 4..."<<endl;
Sleep(999);
cout <<"Starting game in 3..."<<endl;
Sleep(999);
cout <<"Starting game in 2..."<<endl;
Sleep(999);
cout <<"Starting game in 1..."<<endl;
Sleep(999);
gameon=true;
clicks=0;
cout <<"CLICK!"<<endl;
Sleep(9999);
cout <<"Time's up!"<<endl;
gameon=false;
result=clicks/10;
cout <<"You got "<<clicks<<" clicks in 10 seconds. That's "<<result<<" clicks per second!"<<endl;
cout <<""<<endl;
cout <<"If you want to go again, type y and press enter."<<endl;
cin >>inpot;
if(inpot=='y'){
cout <<"Get ready to go again..."<<endl;
cout <<""<<endl;
}
else{
cout <<"Exiting. But first.."<<endl;
cout <<"One divided by zero is.."<<endl;
Sleep(1700);
cout <<"It is uh.."<<endl;
cout <<"OH! I'VE GOT IT! IT IS.."<<endl;
Sleep(2300);
cout <<(1/0)<<endl;//this is where i want a return 0 equivalent.
}
}
}
int main(){
cout <<"You have 10 seconds to click as many times as possible."<<endl;
thread one(keyget);
thread two(other);
one.join();
two.join();
return 0;
}