I don't see anything wrong with this code, yet, I keep getting this error: "error: 'While' was not declared in this scope"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
usingnamespace std;
int main() {
int turns = 1;
int number = 0;
int notThisNumber = 0;
cout << "While ( user == gullible ) 1.0 \n\n";
While(turns != 10); { //Repeat question until turns run out; 10 turns maximum
cout << "Enter any number other than " << notThisNumber << ". \n#"; //Display which number not to enter
cin >> number; //Ask the user for a number
if(number != notThisNumber) {
turns++;
notThisNumber++;
}
}
}
Well first I figured out that there's a huge difference between While and while. When you use the capital 'w' it doesn't work; however, even when I changed it to the lower case w it still didn't work. So thank you erock for telling me to remove the ; because it did work after removing that.
/*
Title: While ( user == gullible )
Author: James Lemire
Date: 10/13/13
Purpose: Show understanding of variables, data types, numeric operators, basic input/output, and logic (if/switch statment(s))
*/
#include <iostream>
usingnamespace std;
int main() {
int turns = 1; //User's turns
int number; //User's number
int notThisNumber = 0; //Computer's number
cout << "While ( user == gullible ) 1.0 \n\n"; //State program's title
while(turns != 11) { //Repeat question until turns run out; 10 turns maximum
cout << "Enter any number other than " << notThisNumber << ". \n#"; //Display which number not to enter
cin >> number; //Ask the user for a number
if(number != notThisNumber) { //User's number doesn't equal computer's number
turns++; //Add 1 turn used by the user
notThisNumber++; //Add 1 to computer's number
}
elseif(number == notThisNumber) { //User's number matched computer's number
cout << "\n\nHey! you weren't supposed to enter " << notThisNumber << "! \n\n\n"; //User failed game
return 0; //End Program
}
}
cout << "\n\nWow, you're more patient then I am, you win. \n\n\n"; //User exceeded 10 turns
return 0; //End Program
}