這裏是一個新手。我有以下幾點:如何終止控制檯?
#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」和「返回」? –
是的,這是對的,抱歉的混亂。 –