我對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