如果他们不从其中一个选项中选择,我怎么会得到一个说错误颜色的else语句?我尝试过if else和else,但即使颜色有正确的选项,它也会显示在我的代码末尾。
我是新手......感谢您的帮助。
enter code here
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
string color1, color2;
string Red, Blue, Yellow;
cout << "When you enter two primary colors, I will tell you\n";
cout << "what color they make when they are mixed together.\n\n";
cout << "Enter red, blue, or yellow: \n" << endl;
getline(cin, color1);
if (color1 == "red" || color1 == "Red")
{
cout << "Please choose from blue or yellow:\n";
getline(cin, color2);
if (color2 == "yellow" ||color2 == "Yellow")
{
cout << "\nGreat you make Orange.\n";
}
if (color2 == "Blue" || color2 == "blue")
{
cout << "\nGreat you make purple.\n";
}
}
if (color1 == "yellow" || color1 == "Yellow")
{
cout << "Please choose from blue or red:\n";
getline(cin, color2);
if (color2 == "red" || color2 == "Red")
{
cout << "\nGreat you make Orange.\n";
}
if (color2 == "Blue" || color2 == "blue")
{
cout << "\nGreat you make Green.\n";
}
}
if (color1 == "Blue" || color1 == "blue")
{
cout << "Please choose from yellow or red:\n";
getline(cin, color2);
if (color2 == "red" || color2 == "Red")
{
cout << "\nGreat you make Purple.\n";
}
if (color2 == "yellow" || color2 == "Yellow")
{
cout << "\nGreat you make Green.\n";
}
}
return 0;
}
enter code here