我的程序跳过用户输入squareSide并保持循环的选项。
代码如下:
do
{
//Displays menu
cout << "Please select a geometric shape." << endl << endl;
cout << "s:" << setw(10) << "Square" << endl;
cout << "c:" << setw(10) << "Circle" << endl;
cout << "d:" << setw(10) << "Diamond" << endl;
cout << "t:" << setw(10) << "Triangle" << endl;
cout << "e:" << setw(10) << "Exit" << endl << endl;
cin >> letter;
cout << "You selected " << letter << endl;
if (letter != EXIT || letter == EXIT1)
{
if (letter == SQUARE || letter == SQUARE1)
{
int squareSide;
int character;
cout <<"\nPlease enter the ASCII character you would like to use to print your square" << endl;
cin >> character;
cout << "\nPlease enter the length of one side of your square"
<< endl;
cin >> squareSide;
for (int x=0; x < squareSide; x++)
{
for (int y = 0; y < squareSide; y++)
{
cout << character;
}
cout << endl;
}
}
}
} while (letter != EXIT && letter != EXIT1);
return 0;
}
所有菜单选项都必须为char。