我对C++编程的概念非常陌生。我希望有一个多条件,如果使用||语句或者在一个语句中和和/或&/&。当我问我的大学教授这件事。她说这是可能的,然后侮辱了我对这个问题的有限知识。我有权访问的所有示例都显示多条语句,只有一条显示||。它不显示它们一起使用。我会学习如何让线路工作。我会附上我的代码。问题领域是编码的最后一个位。多条件if语句C++
# include <iostream>
# include <cstring>
using namespace std;
main()
{
const int maximumHours = 774;
char customerPackage;
double hoursUsed = 0,
packageA = 9.95,
packageB = 14.95,
packageC = 19.95,
overPackageA = 2.00,
overPackageB = 1.00,
overTime = 0,
amountDue = 0,
excessCharged = 0;
cout << "Please enter the customer's package: ";
cin >> customerPackage;
switch (customerPackage)
{
case 'a' :
cout << "Please enter the number of hours used: ";
cin >> hoursUsed;
break;
case 'A' :
cout << "Please enter the number of hours used: ";
cin >> hoursUsed;
break;
case 'b' :
cout << "Please enter the number of hours used: ";
cin >> hoursUsed;
break;
case 'B' :
cout << "Please enter the number of hours used: ";
cin >> hoursUsed;
break;
case 'c' :
cout << "Please enter the number of hours used: ";
cin >> hoursUsed;
break;
case 'C' :
cout << "Please enter the number of hours used: ";
cin >> hoursUsed;
break;
default: cout << "Error."
<< " Please enter the customer's purchased package: ";
cin >> customerPackage;
}
if (customerPackage ='a' || customerPackage ='A' && hoursUsed >= 10)
amountDue = packageA;
else
overTime = packageA - hoursUsed;
excessCharged = overTime * overPackageA;
amountDue = packageA + excessCharged;
}
与'=='比较,而不是'='。并且一定要使用'()'来消除你的条件。否则......怎么了?将你的代码称为“问题区域”并不能让我们继续研究你希望它做什么,而不是那么做。 – 2012-02-09 16:11:54
比较运算符在c/C++上为* == * – Gigi 2012-02-09 16:12:25
另外,请自己帮忙,并在每个比较周围放置括号,以便您和其他人确信&&和||的顺序。以上。 – 2012-02-09 16:13:49