1 Attachment(s)
I need help with a random number generator program.
I am trying to write a simple program that picks a number between 1 and 100, and then lets the user guess what the number is. The program should tell the user if their guess is to high, to low, or correct.
The problem I am having a problem with the program I wrote. Every time I input a number it tells me I am correct even if that number is larger than 100.
I don't what the problem is. Could someone please help.
Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int rand_range(int low, int high)
{
return rand() % (high - low + 1 )+low;
}
int main()
{ int input;
srand(time(NULL));
rand_range(1,100);
cout << "pick a number between 1 and 100 \n";
cin >> input;
if(input=rand_range(1,100))
{
cout << "correct!\n";
}
else if( input != rand_range(1,100))
{
cout<< "wrong!\n";
}
Attachment 13288