【发布时间】:2016-10-04 12:20:36
【问题描述】:
这里是新手。我有以下内容:
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<stdlib.h>
using namespace std;
int main() {
int choice;
double radius, length, width, base, height;
const double PI = 3.14159;
cout << ":Geometry Calculator:\n\n";
cout << "1. Calculate the Area of a Circle \n";
cout << "2. Calculate the Area of a Rectangle \n";
cout << "3. Calculate the Area of a Triangle \n";
cout << "4. Quit\n";
cout << "4. Please pick number: " ;
cin >> choice;
switch (choice) {
case 1:
double aCirc;
cout << "Enter the RADIUS of your Circle: ";
cin >> radius;
aCirc = PI * pow(radius, 2);
cout << "The AREA of your CIRCLE IS: " << aCirc;
break;
case 2:
double aRec;
cout << "Enter the LENGTH and WIDTH of your Rectangle (seprate your numbers with a space): ";
cin >> length >> width;
aRec = length * width;
cout << "The AREA of your Rectangle is: " << aRec;
break;
case 3:
double aTri;
cout << "Enter the BASE and HEIGHT of your Triangle (separate your numbers with a space): ";
cin >> base >> height;
aTri = (base * height) / 2;
break;
case 4:
exit();
default:
cout << "\n You entered an Invalid Number GoodBye No Number" << endl;
}
return 0;
}
我试图在用户按下“4”后立即终止控制台不工作,有人可以帮忙吗?感谢您的时间和专业知识。
【问题讨论】:
-
你的意思是,当用户按下“4”时程序终止,而不是当用户按下“4”和“返回”时?
-
是的,没错,很抱歉造成混乱。
标签: c++ math switch-statement terminate