因此,即时通讯有一个项目,这是我的代码,但我在此代码,而不是只选择一个它选择每一种可能的情况下,这样帮助我有一个问题,这是我的代码也是不知道这是怎么发生,我还在寻找为什么会这样,但也许我需要专业的帮助,所以这是代码
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main()
{
char one, two, three, four;
double a, b, c, d;
cout << "What do you want to find on the square?" << endl;
cout << "A. Area" << endl;
cout << "B. Side" << endl;
cout << "C. Diagonal" << endl;
cout << "D. Perimeter" << endl;
cin >> one ;
one = toupper(one);
switch (one)
{
case 'A':
{ cout << "What is Given" << endl;
cout << "S. Side" << endl;
cout << "D. Diagonal" << endl;
cout << "P. Perimeter" << endl;
cin >> two;
two = toupper(two);
switch (two)
{
case 'S':
{
cout << "Enter Measure of the side." << endl;
cin >> a;
a= a*a;
cout << "The Answer is " << a << endl;
}
case 'D':
{
cout << "Enter Measure of the diagonal" << endl;
cin >> a;
a= pow( a/sqrt(2), 2);
cout << "The Answer is " << a << endl;
}
case 'P':
{
cout << "Enter measure of Perimeter" << endl;
cin >> c;
c= pow(c/4, 2);
cout << "The Answer is " << c << endl;
}
default :
{
}
}
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
小智 5
你需要
break
Run Code Online (Sandbox Code Playgroud)
在每个案件之后.像这样:
case 'S':
{
cout << "Enter Measure of the side." << endl;
cin >> a;
a= a*a;
cout << "The Answer is " << a << endl;
break;
}
Run Code Online (Sandbox Code Playgroud)
对于每一个案例.否则它会经历所有情况而不会破坏,这就是你的情况
| 归档时间: |
|
| 查看次数: |
114 次 |
| 最近记录: |