hello im trying to create a program in which the user has to guess which number the computer picked from a number between 0-10, if the user got it correct the the program displays "Good job" and if not the program displays "0w no, not quite". I recommended that u put the code into your compiler, because there are quite a few error i know this seems like a trivial program, but i need it for a much bigger project im working on.
Thanks in advanced for any helpful responses.
Daniel.B
2nd:
Line 23: it's if not If. Case-sensitive
Line 33: a is not defined within the scope of that function.
Line 32: What is the int n for?
Line 23: Your not passing in any n, but a declaration. Cannot do this.
Write your program out in english step by step, then code it that way.
e.g
Seed random number generator
generate random number between 1-10 etc
Re-read my post, and map our in English what you want to do. You've got some design flaws in your application currently that will prevent it from functioning correctly. Once you have a list of things to achieve in order then you can progress.
#include <iostream>
usingnamespace std;
int main() {
srand(time(NULL));
int numberToGuess = rand() % 10;
int userGuess = 0;
cout << "Enter guess: ";
cin >> userGuess; // WRONG way to do this, see my previous link
//if (userGuess == numberToGuess)
// etc
return 0;
}
rand() return a random number. Don't remember the range.
% 10 gets the remainder of that number when divided by 10, so in this case the number would be 0-9.