If/Else coupon problem

I've been having a difficult time completing this code and getting it to run properly. I'm a beginner with if/else functions (obviously). Any help or advice is appreciated!

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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
 //this program calculates the price for a child or adult haircut with or without a coupon. A salon offers coupons to its customers time to time. Without coupons adult haircut is 15.50 and
//the child haircut is 10.50.Coupons that this salon offers are color coded.The following table
//shows the color code and discount information
//Color code Discount
//Blue(code # 2) 2.59 from adult, 1.50 from kids
//Write a C++ program that asks the user to enter the coupon color and the haircut type(adult, kid)
//and then determine the haircut charge.It is possible that a customers may not have a coupon, in
//that case, no discount will be offered.You can assume that green, blue colors are represented
//using 1 and 2 respectively.
//Develop a C++ program that implements your algorithm









#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
	//set variable
	cout << fixed << setprecision(0) << setw(3) << endl;

	float numAdHaircuts, 
		numChdHaircuts, 
		TotPurchase, 
		DiscountCoup = 0;

	string 
		haveDiscount, 
		DiscountType, 
		coupontype;

	cout << setprecision(2) << fixed << endl;

	//get the number of adult haircuts

	cout << "Enter the number of adult haircuts that are being purchased: ";
	cin >> numAdHaircuts;

	//get the number of children's haircuts

	cout << "Enter the amount of child haircuts that are being purchased: ";
	cin >> numChdHaircuts;

	//ask if the user has a discount coupon

	cout << "Do you have a discount coupon (Y for yes, N for no)? ";
	cin >> haveDiscount;


	//if the user has a discount coupon
	 // ask the user for the discount coupon type

	cout << "Is this discount for an adult or child's ticket (A for adult or C for child)? ";
	cin >> DiscountType;

	cout << "Is it a green or blue coupon? (G/B)\n";
	cin >> coupontype;

	//calculate and display total price
	

	if ((DiscountType == "A") && (coupontype == "G"))
	{
		{
			DiscountCoup = 3.50;
			cout << "Discount: " << DiscountCoup << endl;
		}
		
	else if ((DiscountType == "A") && (coupontype == "B"))
	{
		{
			DiscountCoup = 2.59;
			cout << "Discount: " << DiscountCoup << endl;
		}
	}
	else if ((DiscountType == "C") && (coupontype == "G"))
	{
		{
			DiscountCoup = 2.50;
			cout << "Discount: " << DiscountCoup << endl;
		}
	}
	else if ((DiscountType == "C") && (coupontype == "B"))
		{
			DiscountCoup = 1.50;
			cout << "Discount: " << DiscountCoup << endl;
		}
		else
		{
			cout << DiscountCoup << "is an invalid coupon type" << endl;
		}
	}



	//calculate the purchase amount

	TotPurchase = (numAdHaircuts * 15.50) + (numChdHaircuts * 10.50) - DiscountCoup;
	cout << "Total Purchase: " << TotPurchase << endl;


	return 0;
	}
In function 'int main()':
78:2: error: expected '}' before 'else'
33:3: warning: unused variable 'TotPurchase' [-Wunused-variable]
At global scope:
107:2: error: 'TotPurchase' does not name a type
108:2: error: 'cout' does not name a type
111:2: error: expected unqualified-id before 'return'
112:2: error: expected declaration before '}' token


You have mismatched braces. Either setup your editor to do matched braces for you or get into the habit of typing both of them and go back to fill in what's inside the braces.

Missing iostream header file.

Remember to initialise all of your variables, L34 doesn't do that.
Topic archived. No new replies allowed.