srand funtion?

Ok so I have been following a tutorial on youtube and trying to get my feet wet. I am having a problem in understanding the srand function.

It's your basic high and low guess game. The problem I am having is why it will not compile with the current srand function?

Any helpful responses/links to info would be of great help. I have looked all over google it seems and I can't find anything that covers this specifically. Thanks all.


Errors Seeing:

C++ project\New project\main.cpp|18|error: expected ';' before 'cin'|
C++ project\New project\main.cpp|18|warning: statement has no effect|
C++ project\New project\main.cpp|21|error: 'srand' was not declared in this scope|
C++ project\New project\main.cpp|29|error: expected ';' before 'cin'|
C++ project\New project\main.cpp|43|warning: statement has no effect|

Below is the code:

#include <iostream>
#include<ctime>
using namespace std;

int main ()

{
int iGumballs;
int iUserguess;
int iGuesses = 0;


while (true)

{

("CLS")
cin.clear();
iGuesses = 0;

srand (static_cast < unsigned int > (time(0)));
iGumballs = srand()%1000+1;

cout << "How many gumballs are in the gumball jar?" << endl;

do
{
cout << "Enter your guess: "
cin >> iUserguess;
if (iUserguess > iGumballs)
{
cout << "Too High!" << endl << endl;
}
if (iUserguess < iGumballs)
{
cout << "Too High!" << endl << endl;
}
iGuesses ++;
}while (iUserguess > iGumballs || iUserguess< iGumballs);
cout << "Thats Correct!" << endl << endl;

cout << "You took " << iGuesses << " guesses" << endl <<endl;
("PAUSE");
return 0;
}
}

What is ("CLS")?
What is ("PAUSE")?

Drop the 's' in front of 'srand' here. iGumballs = rand()%1000+1;
Add a semi-colon to the end of this. cout << "Enter your guess: ";

These errors pretty much explain themselves.
Last edited on
Topic archived. No new replies allowed.