im new to C++ and this is a practice i found in a book and im having an issue
the goal of the game is for the computer to hit 0 before the user by subtracting either 1 or 2 at a time
what it is supposed to do is take a number the user inputs and subtract either 1 or 2 from it
then allow the user to input a number and have the computer take that number from the total post it and then subtract another number
BUT it isnt accepting the users input for n to subtract from total what am i doing wrong
im really starting to doubt this book too lol
Code:
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int total, n;
cout << "Welcome to Hell. Wanna play?" << endl;
cout << " Pick a number any number I can handle it." << endl;
cin >> total;
while(true) {
if ((total % 3) == 2){
total = total - 2;
cout << "I'll take 2 whether you like it or not. =P" << endl;
} else{
total--;
cout << " I'm taking one mo ........a." << endl;
}
cout << " Only " << total << "left. Can you even count that high?" << endl;
if (total == 0) {
cout << " HAHAHA I WIN I WIN I WIN !!!!!!!!!!!!!!!!" << endl;
break;
}
cout << "Pick a 1 or 2 I promise it doesn't matter though I'll still win ";
cin >> n;
while (n < 1 || n > 2)
cout << "Hey I thought I told you 1 or 2 try again numskull " << endl;
cin >> n;
total = total -n;
cout << " Okay we are at" << total << " Good job you made me do the math for you now lets move on" << endl;
if (total == 0) {
cout << " Wow what a shocker you won. Good job you beat something that can't even think on its own" << endl;
break;
}
system("PAUSE");
return 0;
}}