# random numbers and responses

• 12-22-2001
diaperdandy
random numbers and responses
the program asks questions in the same order, how can i fix that?
for some questions any answer is seen as correct...?

int main()
{
char ans = 'y';
cout <<"Do you know the nicknames of these colleges . . . \n";
cout <<"All the answers are plural (if possible), lowercase \n";
cout <<"and do not include the word 'the' \n\n.";
while(ans == 'y' || ans == 'Y')
{
int c=0, w=0;
while(w + c < 5)
{
int choice = randMid(1, 9);

if (choice == 1)
{
cout <<"What is the nickname of The University of Maryland?" << endl;
{
cout <<"Correct!" << endl << endl;
c++;
}
else
{
cout <<"Wrong" << endl << endl;
w++;
}
}

if (choice == 2)
{
cout <<"What is the nickname of Duke University?" << endl;
{
cout <<"Correct!" << endl << endl;
c++;
}
else
{
cout <<"Wrong" << endl << endl;
w++;
}
}

if (choice == 3)
{
cout <<"What is the nickname of Georgia Tech University?" << endl;
{
cout <<"Correct!" << endl << endl;
c++;
}
else
{
cout <<"Wrong" << endl << endl;
w++;
}
}

if (choice == 4)
{
cout <<"What is the nickname of The University of Virginia?" << endl;
{
cout <<"Correct!" << endl << endl;
c++;
}
else
{
cout <<"Wrong" << endl << endl;
w++;
}
}

if (choice == 5)
{
cout <<"What is the nickname of North Carolina?" << endl;
{
cout <<"Correct!" << endl << endl;
c++;
}
else
{
cout <<"Wrong" << endl << endl;
w++;
}
}

if (choice == 6)
{
cout <<"What is the nickname of North Carolina State?" << endl;
{
cout <<"Correct!" << endl << endl;
c++;
}
else
{
cout <<"Wrong" << endl << endl;
w++;
}
}

if (choice == 7)
{
cout <<"What is the nickname of Florida State University?" << endl;
{
cout <<"Correct!" << endl << endl;
c++;
}
else
{
cout <<"Wrong" << endl << endl;
w++;
}
}

if (choice == 8)
{
cout <<"What is the nickname of Clemson University?" << endl;
{
cout <<"Correct!" << endl << endl;
c++;
}
else
{
cout <<"Wrong" << endl << endl;
w++;
}
}

if (choice == 9)
{
cout <<"What is the nickname of Wake Forest University?" << endl;
{
cout <<"Correct!" << endl << endl;
c++;
}
else
{
cout <<"Wrong" << endl << endl;
w++;
}

}
}
cout <<"You got " << c <<" correct and " << w <<" wrong!" << endl << endl;
cout << "Do you want to run this program again? (Y or N) --> ";
cin >> ans;
}
return 0;
}

//creates a random number between a low number and high number
int randMid(int low, int high)
{
return low+rand()%(high-low+1);
}
• 12-22-2001
zen
You'll have to seed the random number generator -

srand((unsigned)time(0));

Include <ctime> to use the time function.

strcmp() returns zero if the strings are equal.
• 12-23-2001
diaperdandy
i dont understand
i dont understand after u compare strings how to say if they are equal to do something and if not do something else.
you said it returns 0 if they are true so can u do an example for one of the parts.

thanks,
you're a big help
• 12-23-2001
zen