- Back to Home »
- Subtraction Game(C++ Program)
Posted by : Unknown
#include<iostream>
using namespace std;
int main(){
int total,n;
cout<<"Welcome To Insan Game.Pick a starting total:";
cin >>total;
while(true){
//Pick best response and print results.
if ((total%3)==2){
total=total-2;
cout<<"I am subtracting 2."<<endl;
}else {
total --;
cout<<"I am subtracting 1"<<endl;
}
cout<<"New Total is "<<total<<endl;
if (total ==0){
cout<<"I Win!"<<endl;
break;
}
//Get User's Response ;must be 1 or 2;
cout<<"Enter number to subtract(1 or 2):";
cin>>n;
while(n<1 || n>2) {
cout<<"Input must be 1 or 2"<<endl;
cout<<"Re Enter :";
cin>>n;
}
total=total-n;
cout<<"New Total is"<<total<<endl;
if(total==0){
cout<<"You win!"<<endl;
}
}
return 0;
}