I want to program a program that produces a random number between 1-10, then if the number is correct, says like HEY GOOD JOB and if its not says try AGAIN! also, at any point the user can quit by typing in X.
I know that I can use stuff like cout << "Hey put in a guess now" to prompt the user but I dont know how to accept inputs.
For example, how do I use scanf to do this?
I know that if I use scanf, it takes in a value, but where the heck does it store it?
eg. scanf(%s,guess);
Is that valid? I get an invalid expression error when trying to use that in C++.
You can get a random number 0 through 10 like this.
1 2 3 4 5 6 7 8 9 10 11
#include <ctime>
int main()
{
srand(time(NULL)); // Seed the time
unsignedint val = rand() % 10;
// Do whatever you want with the variable 'val'.
return 0;
};
If you want 10 values, do this
1 2 3 4 5 6 7 8 9 10 11
#include <ctime>
int main()
{
srand(time(NULL)); // Seed the time
unsignedint val = rand() % 9
// Do whatever you want with the variable 'val'.
return 0;
};