if(line_number == 1)
{
//the state selected randomly out of all the states
iStateSelected = rand() % 49; //iState;
//
if(StatesPicked.size() == 51)
{
std::cout << "states finished" << std::endl;
Number = 2;
}
else
{
if(!multiCompare(StatesPicked, State[iStateSelected]))
{
//sends the last state picked to the end of the StatesPicked
StatesPicked.push_back(State[iStateSelected]);
std::cout << "What is the Capital of " << State[iStateSelected] << ": " << std::endl;
std::getline (std::cin, inputString, '\n');
if(inputString == CapitalAnswer)
{
std::cout << CapitalAnswer << " is the Capital of " << State[iStateSelected] << std::endl << std::endl;
}
else
{
std::cout << inputString << " is not the Capital of " << State[iStateSelected] << std::endl;
std::cout << "The Capital of " << State[iStateSelected] << " is " << CapitalAnswer << std::endl << std::endl;
}
}
else
{
std::cout << "choosing another state" <<std::endl;
iStateSelected = rand() % 49; //iState;
std::cout << iStateSelected << std::endl;
}
}
}
}
}
so I want this to run and pick a state randomly and ask what the capital of it is. I have a function that checks to see if the state chosen (goes through a vector of previously chosen states) is equal to any in the vector. I have a problem when they are equal. it will (instead of picking a new number randomly, it picks the same one and tests the same state. so i need the computer to always pick a different number. for example, right now it goes
picks: 24
checks...
24 found
picks another number: 24
check...
24 found
and repeats like that for a while then eventually picks a different number. please help me ASAP i need this program done or working by tomorrow.
I doubt that it will pick the same number EVERYTIME, I do often see repeated selections when using "rand()" though. If you're worried about it why not call "rand()" in a loop until new != old?