Hello everybody, first off I'd like to say thank you to everyone who helped me with my while loop dilema two weeks or so ago.
I am now in the process of expanding the functionality of my guessing program so that it will generate random numbers which are different each time the program is run, I would ideally like to be able to set a range and then compile, as it is now my numbers are constrained only by the limits of the unsigned short
I would like to be able to state an exact range of numbers for example "X-XXXXX" or "X-XX" or "X-XXX" and so on.
I am using bloodshed dev c++ 4 and have used the rand() function successfully to generate a random number however I have not been able to control the range of the number. Anther big problem is that the number doesn't change everytime the program is run, I would like the a unique random number to be generated everytime the program is run.
I have remarked by attempts in this venture thus far in the source code below.
Here is my source code:
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int main()
{
unsigned short correctguess;
unsigned short attempt;
//This is what i'v tried so far in order to get a DIFFERENT random number
//everytime the program runs...
//srand (correctguess);
//int rand(srand n+2);
//And the above has not worked.
rand (correctguess);
//rand is 18467 everytime the program runs.
correctguess = rand();
cout << "Pick a number between 0 and 65535:" << endl;
cin >> attempt;
if (attempt == correctguess) //First try win contingency
cout << "Thats right on the money!" << endl;
while (attempt != correctguess) //Begining of guessloop
{
while (attempt > correctguess) //Begining of high rejection
{
cout << "Try a little lower." << endl;
cin >> attempt;
} //End of high rejection
while (attempt < correctguess) //Begining of low rejection
{
cout << "Thats too low." << endl;
cin >> attempt;
} //End of low rejection
} //End of guessloop
cout << "Thats right on the money!" << endl; //Normal win message
return 0;
}
I would really appreciate any help I recieve and thank you very much!