I am a computer science 1 student and am kinda stuck on my program. The program is called "Guessing Numbers" and is a simple little game of guess the number. My problem is I am not sure how to make the variable "Number" be random every time the loop runs.
How do I make "Number" randomize itself each time the loop runs?
Thanks in advance.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
usingnamespace std;
int main()
{
srand (time(0));
int Guess;
int Attempts;
int Number = rand()%4 + 1;
int Wrong = 0;
int Right = 0;
dofor (Attempts = 0; Attempts < 4; Attempts++)
{
cout << " I am thinking of a number from 1 to 4 can you guess what number it is?" << endl;
cin >> Guess;
if (Guess == Number)
{
cout << "Congratulations you guessed my number!" << endl;
Right++;
}
else
{
cout << "WRONG" << endl;
Wrong++;
}
}
while ( Attempts < 4 );
cout << "You guessed " << Wrong << " wrong and " << Right << " right" << endl;
system ("pause");
return 0;
}