我写了这样一个程序,计算三角形,矩形,圆的面积,怎么修改一下变成一开始先让用户选择三种图形的一种然后再计算?
#include<iostream>
#include<string>
using namespace std;
int main()
{
while(1){
double base, height,area,base2, height2,area2,radius,area3;
cout <<"\nPlease enter the base of the triangle:";
cin >> base;
cout <<"\nPlease enter the height of the triangle:";
cin >> height;
area = base*height/2;
cout<<"\nArea of the triangle is: "<< area << endl;
cout <<"\nPlease enter the base of the rectangle:";
cin >> base2;
cout <<"\nPlease enter the height of the rectangle:";
cin >> height2;
area2 = base2*height2;
cout<<"\nArea of the rectangle is: "<< area2 << endl;
cout <<"\nPlease enter the radius of the circle:";
cin >> radius;
area3 = radius*radius*3.14;
cout<<"\nArea of the circle is: "<< area3 << endl;
}
}
#include<iostream>
#include<string>
using namespace std;
int main()
{
while(1){
double base, height,area,base2, height2,area2,radius,area3;
cout <<"\nPlease enter the base of the triangle:";
cin >> base;
cout <<"\nPlease enter the height of the triangle:";
cin >> height;
area = base*height/2;
cout<<"\nArea of the triangle is: "<< area << endl;
cout <<"\nPlease enter the base of the rectangle:";
cin >> base2;
cout <<"\nPlease enter the height of the rectangle:";
cin >> height2;
area2 = base2*height2;
cout<<"\nArea of the rectangle is: "<< area2 << endl;
cout <<"\nPlease enter the radius of the circle:";
cin >> radius;
area3 = radius*radius*3.14;
cout<<"\nArea of the circle is: "<< area3 << endl;
}
}