我正试图编写一个程序来计算体积和添加到球形或矩形形状的鱼缸中的空调量。忽略第二条语句
我想要问用户坦克是否是圆形的,他们会回答'y','Y'还是'n','N'。但是,每当我运行程序并输入n或N时,它仍然运行if或y语句。
请注意,我对这一切都很陌生。这是编程和逻辑类的介绍。
这里是我的源代码:
#include <iostream>
using namespace std;
int main()
{
char Circle = ' ';
int RADIUS = 0;
int HEIcircle = 0;
int LEN = 0;
int WID = 0;
int HEI = 0;
double AMTcondCIR;
double AMTcondREC;
cout << "Is tank circular? ";
cin >> Circle;
if (Circle = 'Y' or 'y')
{
cout << "Enter radius: ";
cin >> RADIUS;
cout << "Enter height: ";
cin >> HEIcircle;
AMTcondCIR = ((4/3) * 3.14 * (RADIUS^3)) * 0.01;
cout << "Amount of Conditioner to add (in mL): " << AMTcondCIR << endl;
}
if (Circle = 'N' or 'n')
{
cout << "Enter length: ";
cin >> LEN;
cout << "Enter width: ";
cin >> WID;
cout << "Enter height: ";
cin >> HEI;
AMTcondREC = (LEN * WID * HEI) * 0.01;
cout << "Amount of Conditioner to add (in mL): " << AMTcondREC << endl;
}
system("pause");
return 0;
}
,您在学习什么书?更具体地说,是什么让你认为你的预期比较的作用是'if(Circle ='Y'或'y')'?您应该可以获得比现在更高质量的学习C++源代码 – PlasmaHH