Having a Blonde moment
Oct 16, 2012 at 2:05am
I keep getting parse errors before else and return. I've tried indenting and also switching to if/else statements. Any clues?
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
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float regularPrice = 00.00, couponValue = 00.00, amountPaid = 00.00, Savings = 00.00;
char couponType, couponUsed;
cout << "What is the price of the items?" << endl;
cin >> regularPrice;
cout << "Is there a coupon?" << endl;
cin >> couponUsed;
if (couponUsed='Y')
{
cout << "What type of coupon is it?" << endl;
cin >> couponType;
}
switch (couponType)
{
case'C':
cout << "What is the coupon's value?" << endl;
cin >> couponValue;
Savings = couponValue;
amountPaid = regularPrice - Savings;
cout << left << setw(12) << "ITEM COST " << "= $ " << fixed << setprecision(2) << regularPrice << endl;
cout << left << setw(12) << "COUPON USED " << "= " << couponUsed << endl;
cout << left << setw(12) << "COUPON TYPE " << "= " << couponType << endl;
cout << left << setw(12) << "SAVINGS " << "= $ " << fixed << setprecision(2) << Savings << endl;
cout << left << setw(12) << "PAYMENT DUE " << "= $ " << fixed << setprecision(2) << amountPaid << endl;
break;
case'P':
cout << "What is the coupon's percentage?";
cin >> couponValue;
Savings = regularPrice * (couponValue/100.0);
amountPaid = regularPrice - Savings;
cout << left << setw(12) << "ITEM COST " << "= $ " << fixed << setprecision(2) << regularPrice << endl;
cout << left << setw(12) << "COUPON USED " << "= " << couponUsed << endl;
cout << left << setw(12) << "COUPON TYPE " << "= " << couponType << endl;
cout << left << setw(12) << "SAVINGS " << "= $ " << fixed << setprecision(2) << Savings << endl;
cout << left << setw(12) << "PAYMENT DUE " << "= $ " << fixed << setprecision(2) << amountPaid << endl;
break;
default: cout << "Invalid Coupon" << endl;
}
else
{
amountPaid = regularPrice;
cout << left << setw(12) << "ITEM COST " << "= $ " << fixed << setprecision(2) << regularPrice << endl;
cout << left << setw(12) << "PAYMENT DUE " << "= $ " << fixed << setprecision(2) << amountPaid << endl;
}
return 0;
}
|
Oct 16, 2012 at 2:09am
As is it is written, it looks like you have a switch statement (line 19-45) stuck between the end of the if and the beginning of the else.
Oct 16, 2012 at 2:11am
Yeah I was trying to write the switch statement into the if/else statement based off line 17.
Oct 16, 2012 at 2:14am
Well, it has to be in one or the other (either in the if statement or the else), not in between the two of them.
Oct 16, 2012 at 2:14am
Knew it was a blonde moment. Thank You.
Topic archived. No new replies allowed.