#include <iostream>
#include <math.h>
using namespace std;
int main() {
double radius = 0.00;
double height = 0.00;
double width = 0.00;
double side = 0.00;
double Area = 0.00;
const double PI = atan(1.0)*4;
string input = "none";
while (input != "0") {
cout << "Shape Menu:
(r) rectangle
(s) square
(c) circle
(0) exit" << endl;
cin >> input;
if (input == "r"){
cout << "Please enter a floating point value for the height of the rectangle." << endl;
cin >> height;
cout << height;
while (height <= 0)
{
cin.clear();
cin.ignore(1000,
);
cout << "Your input was invalid. Please input a floating point value greater than 0.";
cin >> height;
}
cout << "Please enter a floating point value greater than 0 for the width of the rectangle." << endl;
cin >> width;
while (width <= 0)
{
cin.clear();
cin.ignore(1000,
);
cout << "Your input was invalid";
cin >> width;
}
Area = height*width;
cout << "The area of a rectangle with those dimensions is " << Area << "units squared." << endl;
}
else if(input == "s"){
cout << "Please enter a floating point value for the length of the side." << endl;
cin >> side;
if (cin.fail())
cout << "Please enter a floating point value.";
Area = side*side;
cout << "The area of a square with those dimensions is " << Area << "units squared" << endl;
}
else if(input == "c"){
cout << "Please enter a floating point value for the length of the radius." << endl;
cin >> radius;
if (cin.fail())
cout << "Please enter a floating point value.";
Area = radius*radius*PI;
cout << "The area of a circle with those dimensions is " << Area << "units squared." << endl;
}
else if(input == "0"){
break;
}
else{
cout << "Your input does not match one of the options suggested. Please type r, s, c to get the area of a shape, or type 0 to exit." << endl;
}
}
return 0;
}
我正试图起草一个方案,要求用户从形状的菜单中提取,然后要求为每一类产品提供某些投入,以确定该地区。 我现在面临的问题是,在人们为rad子或高湿度提出答案时,如何发现错误。 我正试图为试金字书写错误是为了初步不正确的投入而工作,然而,一旦用户再次出现输入错误,就会开始无限循环。