I don't understand my error, I get 2 every time. I coded this in C++ obviously. If someone could please help me that would be great, any help would be great.
source code: ---------------
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int iG;
int uN;
iG = rand() % 10 + 1;
cout << "Enter a number, 1-10 to see if I can guess it." << endl;
cin >> uN;
if(uN<1){
cout << "The number you entered is less than 1, make sure it is 1-10." << endl;
cout << "Enter anything and ENTER to exit the program." << endl;
int q;
return 0;
}
if(uN>10){
cout << "The number you entered is over 10, 1-10!" << endl;
cout << "Enter anything and ENTER to exit the program." << endl;
int q;
return 0;
}
if(uN==iG){
cout << "Yes! I guessed your number! It is" << uN << endl;
cout << "Enter anything and ENTER to exit the program." << endl;
int q;
return 0;
}
if(uN!=iG){
cout << "Aww! I didn't guess correctly. I guessed "<< iG << "and you guessed " << uN << endl;
cout << "Enter anything and ENTER to exit the program." << endl;
int q;
return 0;
}
}
#include <ctime> and put the srand(time(NULL)) anywhere in your code to get different random numbers when using the rand() method. Without putting srand(time(NULL)), rand() will always generate the same random number. Hope this helps