我需要以下 c++ 代码的帮助,尝试continue
在程序末尾添加 a ,以便它为用户指定矩形尺寸并要求用户再次重做程序。
在程序的最后部分编译并运行它,而不用愚蠢的 if 和 else 语句,它就可以工作了。但是使用continue
/ 递归它失败了。大声笑。我=菜鸟。
int main()
{
int height, width, tmp, tmp2;
char continue;
cout << "Please Enter The Height Of A Rectangle (whole numbers only): ";
height:
cin >> height;
if(height<1)
{
cout << " Please Enter A Height Of Between 1 And 20: ";
goto height;
}
cout << "Please Enter The Width Of A Rectangle (whole numbers only): ";
width:
cin >> width;
if(width<1)
{
cout << " Please Enter A Width Of Between 1 And 38: ";
goto width;
}
cout << ' '; // Add a space at the start (to neaten top)
for(tmp=0; tmp!=width; tmp++) cout << "__"; // Top Of Rectangle
for(tmp=0; tmp!=(height-1); tmp++)
{
cout << "\n|"; // Left Side Of Rectangle
for(tmp2=0; tmp2!=width; tmp2++) cout << " "; // Create A Gap Between Sides
cout << "|";
} // Right Side Of Rectangle
cout << "\n|"; // Left Side Of Bottom Of Rectangle to neaten bottom)
for(tmp=0; tmp!=width; tmp++) cout << "__"; // Bottom Of Rectangle
cout << '|'; // Right Side Of Bottom Of Rectangle (to neaten bottom)
cout << "Type 'y' if you would like to continue and any other combination to quit.";
continue:
cin >> continue;
if(continue == 'y')
{
main();
cout << "\n\n";
system("PAUSE");
return 0;
}
else
cout << "\n\n";
system("PAUSE");
return 0;
}