我正試圖編寫一個程序來計算體積和添加到球形或矩形形狀的魚缸中的空調量。忽略第二條語句
我想要問用戶坦克是否是圓形的,他們會回答'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