我需要添加什么,以便它不会连续选择数字为 8,而是选择数字 1 到 9 中的任何一个?斯兰德?
int main()
{
int iRand = (rand() % 9+1);
if (iRand==1)
{
cout << "The planet of the day is Mercury!" <<endl;
cout << "Mercury is the closest planet to the sun." <<endl;
}
else if (iRand==2)
{
cout << "The planet of the day is Venus!" <<endl;
cout << "Venus is the hottest planet in our solar system." <<endl;
}
// .... 3..4..5..6..7..8
else
{
cout << "The planet of the day is Pluto!" <<endl;
}
return 0;
}