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!
//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>
usingnamespace 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;
}
elseif ((DiscountType == "A") && (coupontype == "B"))
{
{
DiscountCoup = 2.59;
cout << "Discount: " << DiscountCoup << endl;
}
}
elseif ((DiscountType == "C") && (coupontype == "G"))
{
{
DiscountCoup = 2.50;
cout << "Discount: " << DiscountCoup << endl;
}
}
elseif ((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.