I see you haven't fixed line 39 as I pointed out in my forum reply.
Line 9,53,61: Should be 'S', not "S". Single quote, not double.
Line 20 should be: right << setw(21) Should be <<, not <
Line 73,74: Missing a close quote
cout << "Total payment for Social media marketing (M) is :"
cout << "Total payment for Email marketing (t) is :"
Line 43: You're using the return value from calPayment, but calPayment doesn't return a value if you fall through the if statements.
Lines 54,56,58: round() returns a double. discount is an int. If you want to assign a double to an int, you must cast it.
Line 75: You need to adjust your parens:
int highest = total_s > total_m ? (total_s > total_e ? total_s : total_e) : (total_m > total_e ? total_m : total_e);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
using std::setw;
using std::right;
int calPayment(char service, int duration)
{
if (service == 's' || service == 'S')
return(duration * 2000);
if (service == 'm' || service == 'M')
return(duration * 1500);
if (service == 'e' || service == 'E')
return(duration * 990);
return -1; // Avoid compiler warning
}
void displayPayment(int payment, int discount, int afterDiscount)
{
cout << "Total purchase before discount" << right << setw(5) << ": " << payment << endl;
cout << "Total discount" << right << setw(21) << ": " << discount << endl;
cout << "Total Purchase after discount " << right << setw(6) << ": " << afterDiscount << endl;
}
int main()
{
int total_s, total_m, total_e, totalPayment;
total_s = 0;
total_m = 0;
total_e = 0;
totalPayment = 0;
int number, duration, payment;
char service;
for (int i = 1; i < 6; i++)
{ // Begin for loop
cout << "Customer number " << right << setw(21) << ": ";
cin >> number;
cout << "Please enter the service code :";
cin >> service;
cout << "Please enter the duration of service purchase : ";
cin >> duration;
payment = calPayment(service, duration);
cout << "Customer number " << right << setw(20) << ": " << number << endl;
cout << "The code of service is " << right << setw(16) << ": " << service << endl;
cout << "The duration of service is " << right << setw(9) << ": " << duration << endl;
cout << "The payment is " << right << setw(19) << ": " << payment << endl;
int discount = 0;
if (duration > 12)
{
if (service == 's' || service == 'S')
discount = (int)round((duration * 2000) * 0.1);
if (service == 'm' || service == 'M')
discount = (int)round((duration * 1500) * 0.1);
if (service == 'e' || service == 'E')
discount = (int)round((duration * 990) * 0.1);
}
if (service == 's' || service == 'S')
total_s += payment;
if (service == 'm' || service == 'M')
total_m += payment;
if (service == 'e' || service == 'E')
total_e += payment;
int afterDiscount = payment - discount;
totalPayment += afterDiscount;
displayPayment(payment, discount, afterDiscount);
} // End for loop
cout << "Total payment for search engine optimization (S) is : " << total_s << endl;
cout << "Total payment for Social media marketing (M) is :" <<right<<setw(7)<<": "<<total_m<<endl;
cout << "Total payment for Email marketing (t) is :" <<right<<setw(14)<<" : "<<total_e<<endl;
int highest = total_s > total_m ? (total_s > total_e ? total_s : total_e) : (total_m > total_e ? total_m : total_e);
cout << "Service with the highest total payment is" << right << setw(13) << ": " << highest << endl;
cout << "The total payment from all customers (5) is : " << totalPayment << "(afterDiscount)" << endl;
}
|