こんにちは、私は課題に取り組んでいます。何時間も費やしましたが、プログラムの最後に「Total Commission」と「Total due」が加算されない理由がわかりません。私は初心者なので、正しい方向に導くことができるものは何でも大歓迎です. ありがとう。
オリジナルコード
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const double PC_BASE_SALES = 6000.00, //PC is Personal Computers
PC_COMMISSION = 0.12,
PRINTER_BASE_SALES = 2500.00,
PRINTER_COMMISSION = 0.10,
ACCESSORIE_BASE_SALES = 2000.00,
ACCESSORIE_COMMISSION = 0.10,
MAINTENANCE_BASE_SALES = 1500.00,
MAINTENANCE_COMMISSION = 0.06;
double baseSalary = 0.00,
pcSales = 0.00,
printerSales = 0.00,
accessorieSales = 0.00,
maintenanceSales = 0.00,
totalCommission = 0.00,
totalDue = 0.00,
noCommission = 0.00,
pcCommission = baseSalary * PC_COMMISSION,
printerCommission = baseSalary * PRINTER_COMMISSION,
accessorieCommission = baseSalary * ACCESSORIE_COMMISSION,
maintenanceCommission = baseSalary * MAINTENANCE_COMMISSION;
int idNumber; //salesman identification number
do
{
cout << "Please Enter Salesman Identification or -999 to Terminate ";
cin >> idNumber;
if (idNumber == -999)
return 0;
else
cout << "Please Enter Salesman Base Salary\t\t\t ";
cin >> baseSalary;
cout << "Please Enter Personal Computer Sales\t\t\t ";
cin >> pcSales;
cout << "Please Enter Printer Sales\t\t\t\t ";
cin >> printerSales;
cout << "Please Enter Accessories Sales\t\t\t\t ";
cin >> accessorieSales;
cout << "Please Enter Maintenance Sales\t\t\t\t ";
cin >> maintenanceSales;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << "\t\t\t My Computer Company\n ";
cout << endl;
cout << "\t\t\t Commission Statement\n ";
cout << endl;
cout << "\t\t\t Salesman Number " << idNumber << endl;
cout << endl;
cout << "\t\t ********************************\n";
cout << endl;
cout << fixed;
cout << setprecision(2);
cout << left << setw(20) << "Product";
cout << right << setw(20) << "Sales Amount";
cout << right << setw(20) << "Commission";
cout << "\n" << endl;
cout << left << setw(20) << "Personal Computers";
cout << right << setw(20) << pcSales;
while (pcSales > PC_BASE_SALES)
{
double pcCommission = baseSalary * PC_COMMISSION;
cout << right << setw(20) << pcCommission;
cout << "\n" << endl;
pcCommission += totalCommission;
break;
}
while (pcSales < PC_BASE_SALES)
{
cout << right << setw(20) << noCommission;
cout << "\n" << endl;
break;
}
cout << left << setw(20) << "Printers";
cout << right << setw(20) << printerSales;
while (printerSales > PRINTER_BASE_SALES)
{
double printerCommission = baseSalary * PRINTER_COMMISSION;
cout << right << setw(20) << printerCommission;
cout << "\n" << endl;
printerCommission += totalCommission;
break;
}
while (printerSales < PRINTER_BASE_SALES)
{
cout << right << setw(20) << noCommission;
cout << "\n" << endl;
break;
}
cout << left << setw(20) << "Accessories";
cout << right << setw(20) << accessorieSales;
while (accessorieSales > ACCESSORIE_BASE_SALES)
{
double accessorieCommission = baseSalary * ACCESSORIE_COMMISSION;
cout << right << setw(20) << accessorieCommission;
cout << "\n" << endl;
accessorieCommission += totalCommission;
break;
}
while (accessorieSales < ACCESSORIE_BASE_SALES)
{
cout << right << setw(20) << noCommission;
cout << "\n" << endl;
break;
}
cout << left << setw(20) << "Maintenance";
cout << right << setw(20) << maintenanceSales;
while (maintenanceSales > MAINTENANCE_BASE_SALES)
{
double maintenanceCommission = baseSalary * MAINTENANCE_COMMISSION;
cout << right << setw(20) << maintenanceCommission;
cout << "\n" << endl;
maintenanceCommission += totalCommission;
break;
}
while (maintenanceSales < MAINTENANCE_BASE_SALES)
{
cout << right << setw(20) << noCommission;
cout << "\n" << endl;
cout << endl;
break;
}
cout << endl;
totalCommission = pcCommission + printerCommission + accessorieCommission +
maintenanceCommission;
totalDue = baseSalary + totalCommission;
cout << left << setw(20) << "Total Commission";
cout << right << setw(40) << totalCommission;
cout << "\n" << endl;
cout << left << setw(20) << "Base Pay";
cout << right << setw(40) << baseSalary;
cout << "\n" << endl;
cout << left << setw(20) << "Total Due";
cout << right << setw(40) << totalDue;
cout << "\n" << endl;
} while ( idNumber != -999);
system ("PAUSE");
return 0;
更新されたコード
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const double PC_BASE_SALES = 6000.00, //PC is Personal Computers
PC_COMMISSION = 0.12,
PRINTER_BASE_SALES = 2500.00,
PRINTER_COMMISSION = 0.10,
ACCESSORIE_BASE_SALES = 2000.00,
ACCESSORIE_COMMISSION = 0.10,
MAINTENANCE_BASE_SALES = 1500.00,
MAINTENANCE_COMMISSION = 0.06;
double baseSalary = 0.00,
pcSales = 0.00,
printerSales = 0.00,
accessorieSales = 0.00,
maintenanceSales = 0.00,
totalCommission = 0.00,
totalDue = 0.00,
noCommission = 0.00,
pcCommission = baseSalary * PC_COMMISSION,
printerCommission = baseSalary * PRINTER_COMMISSION,
accessorieCommission = baseSalary * ACCESSORIE_COMMISSION,
maintenanceCommission = baseSalary * MAINTENANCE_COMMISSION;
int idNumber; //salesman identification number
do
{
cout << "Please Enter Salesman Identification or -999 to Terminate ";
cin >> idNumber;
if (idNumber == -999)
return 0;
else
cout << "Please Enter Salesman Base Salary\t\t\t ";
cin >> baseSalary;
cout << "Please Enter Personal Computer Sales\t\t\t ";
cin >> pcSales;
cout << "Please Enter Printer Sales\t\t\t\t ";
cin >> printerSales;
cout << "Please Enter Accessories Sales\t\t\t\t ";
cin >> accessorieSales;
cout << "Please Enter Maintenance Sales\t\t\t\t ";
cin >> maintenanceSales;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << "\t\t\t My Computer Company\n ";
cout << endl;
cout << "\t\t\t Commission Statement\n ";
cout << endl;
cout << "\t\t\t Salesman Number " << idNumber << endl;
cout << endl;
cout << "\t\t ********************************\n";
cout << endl;
cout << fixed;
cout << setprecision(2);
cout << left << setw(20) << "Product";
cout << right << setw(20) << "Sales Amount";
cout << right << setw(20) << "Commission";
cout << "\n" << endl;
cout << left << setw(20) << "Personal Computers";
cout << right << setw(20) << pcSales;
if (pcSales > PC_BASE_SALES)
{
double pcCommission = baseSalary * PC_COMMISSION;
cout << right << setw(20) << pcCommission;
cout << "\n" << endl;
totalCommission += pcCommission;
}
if (pcSales < PC_BASE_SALES)
{
cout << right << setw(20) << noCommission;
cout << "\n" << endl;
}
cout << left << setw(20) << "Printers";
cout << right << setw(20) << printerSales;
if (printerSales > PRINTER_BASE_SALES)
{
double printerCommission = baseSalary * PRINTER_COMMISSION;
cout << right << setw(20) << printerCommission;
cout << "\n" << endl;
totalCommission += printerCommission;
}
if (printerSales < PRINTER_BASE_SALES)
{
cout << right << setw(20) << noCommission;
cout << "\n" << endl;
}
cout << left << setw(20) << "Accessories";
cout << right << setw(20) << accessorieSales;
if (accessorieSales > ACCESSORIE_BASE_SALES)
{
double accessorieCommission = baseSalary * ACCESSORIE_COMMISSION;
cout << right << setw(20) << accessorieCommission;
cout << "\n" << endl;
totalCommission += accessorieCommission;
}
if (accessorieSales < ACCESSORIE_BASE_SALES)
{
cout << right << setw(20) << noCommission;
cout << "\n" << endl;
}
cout << left << setw(20) << "Maintenance";
cout << right << setw(20) << maintenanceSales;
if (maintenanceSales > MAINTENANCE_BASE_SALES)
{
double maintenanceCommission = baseSalary * MAINTENANCE_COMMISSION;
cout << right << setw(20) << maintenanceCommission;
cout << "\n" << endl;
totalCommission += maintenanceCommission;
}
if (maintenanceSales < MAINTENANCE_BASE_SALES)
{
cout << right << setw(20) << noCommission;
cout << "\n" << endl;
cout << endl;
}
cout << endl;
totalCommission = pcCommission + printerCommission + accessorieCommission + maintenanceCommission;
totalDue = baseSalary + totalCommission;
cout << left << setw(20) << "Total Commission";
cout << right << setw(40) << totalCommission;
cout << "\n" << endl;
cout << left << setw(20) << "Base Pay";
cout << right << setw(40) << baseSalary;
cout << "\n" << endl;
cout << left << setw(20) << "Total Due";
cout << right << setw(40) << totalDue;
cout << "\n" << endl;
} while ( idNumber != -999);
system ("PAUSE");
return 0;
}