Making Algorithms Using Random Numbers

Hello!

I'm new to C++, and I'm trying to create a program that will use an algorithm which adds two random numbers that I have generated within a specified range. I have generated two random numbers, each with a different range, but I keep getting the same error no matter how I try to define the variables that I am using to range the random numbers to. Here's the part of the code I am referring to:

srand ((unsigned)time(0));
int AddNum1; //Define the variable of the random number to limited between 100 and 300
int AddNum2; //Define the second variable of the random number to be between 0 and 100
int correct;
int AddAnswer;

switch (HELP) //A switch will be used to navigate through the choices from the menu
{

case 1: srand((unsigned)time(0));
AddNum1 = rand() % 200 + 100; //Setting the range to the first random int
cout << setw(4) << rand() << endl;
srand((unsigned)time(0));
AddNum2 = rand() % 101; //Seeting the range for the second random int
cout << "+";
cout << setw(3) << rand () << endl;
cout << setw(4) << "---" << endl;
cout << correct = AddNum1 + AddNum2;
cin >> correct;

In bold is where the error appears. The error reads: error C2679: binary '=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\ostream(584): could be 'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator =(const std::basic_ostream<_Elem,_Traits> &)'
etc.
You only seed the PRNG once with srand(). Then you call rand() to get the next number in the sequence.

You're calling srand() multiple times, which isn't quite right.

As for the syntax error, you should have:
1
2
correct = AddNum1 + AddNum2;
cout << correct;
I think. At any rate, the = has lower precidence than << so you need to rearrange that code; either break it out or use parentheses.
http://msdn.microsoft.com/en-us/library/126fe14k.aspx
Sweet. Thank you! I managed to figure out extra errors that I had hidden in my code along with that.
Topic archived. No new replies allowed.