我想设置不同的时间相等,以便我可以继续与其他语句。但由于某种原因,它似乎不想这样做。不仅如此,它似乎只承认我拥有的第一个“TIE”,即使它也应该承认其他的。我究竟做错了什么?为什么我不能在If语句中定义多个相等的变量?
if (time1 < time2 && time3)
{
cout << "\nCongratualations " << racer1 << "!!! " << "You are the winner!!" << endl;
cout << "\n***** Your winning time is: " << time1 << " *****" << endl;
}
else if (time2 < time1 && time3)
{
cout << "\nCongratualations " << racer2 << "!!! " << "You are the winner!!" << endl;
cout << "\n***** Your winning time is: " << time2 << " *****" << endl;
}
else if (time3 < time1 && time2)
{
cout << "\nCongratualations " << racer3 << "!!! " << "You are the winner!!" << endl;
cout << "\n***** Your winning time is: " << time3 << " *****" << endl;
}
else if ((time1 == time2) < time3)
{
cout << "\nWe have a TIE " << racer1 << " and " << racer2 << " win!!" << endl;
cout << "\n***** Your winning time is: " << time1 << " *****" << endl;
}
else if ((time2 == time3) < time1)
{
cout << "\nWe have a TIE " << racer2 << " and " << racer3 << " win!!" << endl;
cout << "\n***** Your winning time is: " << time2 << " *****" << endl;
}
else if ((time3 == time1) < time2)
{
cout << "\nWe have a TIE " << racer1 << " and " << racer3 << " win!!" << endl;
cout << "\n***** Your winning time is: " << time3 << " *****" << endl;
}
if (time1 == (time2 == time3))
{
cout << "\nWe have a 3 way TIE!! No winner for this Race..." << endl;
cout << "\n***** Your winning time is: " << time1 << " *****" << endl;
}
请取消您的Wall Of Code并将其替换为仅包含重现问题所需代码的简化示例。 –
它看起来像你正在编写的代码基于你有*猜测*语法的手段来表示。这只会让你陷入麻烦。这里值得回到基础知识来了解每个操作符*实际*所做的事情。 –