can anyone help? I need ASAP.

Jul 11, 2021 at 7:58am
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
80
81
82
83
84
85
#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);
}

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++)
    
}

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=round((duration*2000)*0.1);
    
    if(service=='m'||service=='M')
    discount=round((duration*1500)*0.1);
    
    if(service=='e'||service=='E')
    discount=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);
}

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;
}
Last edited on Jul 11, 2021 at 8:40am
Jul 11, 2021 at 8:32am
Well, you dumped some code (unreadable because you didn't use code tags) and failed to state what your problem was.
Jul 11, 2021 at 8:37am
What help do you need?

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

Line 39: This } terminates main. All the remaining statements are outside of a function which is an error. Did you mean { ?
Jul 11, 2021 at 9:14am
There are several syntax errors. Perhaps:

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
#include <iomanip>
#include <cmath>

using std::setw;
using std::right;
using std::cout;
using std::cin;

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 0;
}

double caldiscount(char service, int duration)
{
	if (duration > 12) {
		if (service == 's' || service == 'S')
			return round((duration * 2000) * 0.1);

		if (service == 'm' || service == 'M')
			return round((duration * 1500) * 0.1);

		if (service == 'e' || service == 'E')
			return round((duration * 990) * 0.1);
	}

	return 0;
}

void displayPayment(int payment, double discount, double afterDiscount)
{
	cout << "Total purchase before discount" << right << setw(6) << ": " << payment << '\n';
	cout << "Total discount" << right << setw(22) << ": " << discount << '\n';
	cout << "Total Purchase after discount " << right << setw(6) << ": " << afterDiscount << '\n';
}

int main()
{
	int total_s {}, total_m {}, total_e {};
	double totalPayment {};

	for (int i = 1; i < 6; ++i) {
		int number {}, duration {};
		char service {};

		cout << "Customer number: ";
		cin >> number;

		cout << "Please enter the service code: ";
		cin >> service;

		cout << "Please enter the duration of service purchase: ";
		cin >> duration;

		const auto payment {calPayment(service, duration)};

		cout << "Customer number " << right << setw(20) << ": " << number << '\n';
		cout << "The code of service is " << right << setw(13) << ": " << service << '\n';
		cout << "The duration of service is " << right << setw(9) << ": " << duration << '\n';
		cout << "The payment is " << right << setw(21) << ": " << payment << '\n';

		const auto discount {caldiscount(service, duration)};

		if (service == 's' || service == 'S')
			total_s += payment;

		if (service == 'm' || service == 'M')
			total_m += payment;

		if (service == 'e' || service == 'E')
			total_e += payment;

		const auto afterDiscount {payment - discount};

		totalPayment += afterDiscount;
		displayPayment(payment, discount, afterDiscount);
	}

	cout << "Total payment for search engine optimization (S) is : " << total_s << '\n';
	cout << "Total payment for Social media marketing (M) is " << right << setw(6) << ": " << total_m << '\n';
	cout << "Total payment for Email marketing (t) is " << right << setw(13) << " : " << total_e << '\n';

	const auto 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 << '\n';
	cout << "The total payment from all customers (5) is" << right << setw(11) << " : " << totalPayment << " (afterDiscount)\n";
}


Note. Check L93 produces the correct result.

Also note that there's no checks for valid/invalid input.

Last edited on Jul 11, 2021 at 9:43am
Jul 11, 2021 at 3:52pm
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;
}

Last edited on Jul 11, 2021 at 3:52pm
Topic archived. No new replies allowed.