你能說出什麼是錯誤嗎?它編譯並運行正常,但程序不會結束。C++程序不會結束
我正在使用dev C++。該代碼是:
#include <iostream>
using namespace std;
main()
{
char num;
again:
int usr;
float area;
cout << "\nEnter 1 to calculate area of rectangle\n";
cout << "Enter 2 to calculate area of trapezoid\n";
cout << "\nEnter your choice: ";
cin >> usr;
if (usr == 1)
{
double width, length;
cout << "Enter the width of rectangle: ";
cin >> width;
cout << "Enter the length of rectangle: ";
cin >> length;
area = length * width;
cout << "The area of rectangle is: " << area;
}
if (usr == 2) {
double base1, base2, height;
cout << "Enter the base 1 of trapezoid: ";
cin >> base1;
cout << "Enter the base 2 of trapezoid: ";
cin >> base2;
cout << "Enter the height of trapezoid: ";
cin >> height;
area = (((base1 + base2)/2) * height);
cout << "The area of trapezoid is: " << area;
}
cout << "\n\ndo you want to do another calculation?";
cin >> num;
{
goto again;
}
if (num == 'y')
{
goto again;
}
if (num == 'n') {
exit(0);
}
}
你期望什麼'cin >> num; {goto again; }'做什麼? – Andrew
我說你應該改進它第一 –
如果我刪除括號其結束,並不會問第二次我希望它再次問,如果我說'是'是它應該再次做計算,當我說'N'沒有它退出但它不會退出其開始它 –