Hi alexandrap98,
You have a few syntax errors: (the line numbers below refer to your code above, not the code beneath)
a) line 47, you're using "=" instead of "==" and also have a semi-colon at the end which you shouldn't do.
b) same semi-colon error on line 57. No semi-colon required.
c) If you're going to use a bunch of "if" conditions at all, I would have thought it was better to use else-if statements (see modified code below). Also see (e).
d) line 70, you use "counter < 10" whereas in the other memberships you use "counter <=10".
e) I'm curious … You already know what the membership type is by the time you get to the set of "if" statements. Wouldn't it be easier just to put the code for each of the membership "if" statements into the relevant switch statement? Or maybe I'm missing something.
Anyway, your same code is below, with those few bits amended (except for "(e)"), and it seems to work okay.
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
|
#include <iostream>
#include <cstdlib>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
const double GOLD = .01, SILVER = .02, BRONZE = .04, BASE = 1200;
int membership;
double rate, year, memfee;
do {
cout << " Welcome to Ronada's Strikeforce Gym!! " << endl;
cout << "x------------------------------------x" << endl;
cout << " Membership Fee Calculator " << endl;
cout << "1. Gold " << endl;
cout << "2. Silver " << endl;
cout << "3. Bronze " << endl;
cout << "4. Quit " << endl;
cout << endl;
cout << "Please enter your membership level (1-3 Enter 4 to Quit) >" << endl;
cin >> membership;
while (membership < 1 || membership > 4)
{
cout << "Choice must be between 1 and 4" << endl;
cin >> membership;
}
switch (membership)
{
case 1: rate = GOLD;
break;
case 2: rate = SILVER;
break;
case 3: rate = BRONZE;
break;
default:
; // do something else
}
cout << fixed << setprecision(2);
memfee = BASE;
if (membership == 1)
{
for (int counter = 1; counter <= 10; counter++)
{
year = memfee * rate;
memfee += year;
cout << "Year " << counter << " $" << memfee << endl;
}
}
else if (membership == 2)
{
for (int counter = 1; counter <= 10; counter++)
{
year = memfee * rate;
memfee += year;
cout << "Year " << counter << " $" << memfee << endl;
}
}
else if (membership == 3)
{
for (int counter = 1; counter <=10; counter++)
{
year = memfee * rate;
memfee += year;
cout << "Year " << counter << " $" << memfee << endl;
}
}
} while (membership != 4);
if (membership == 4)
cout << " Thank you for using Rhonda's Fee Calculator! ";
system("pause");
return 0;
}
|
I hope that helps. Oh, also added a "default" switch statement too.
P.S. What I meant in (e) is something like the code below:
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
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const double GOLD = .01, SILVER = .02, BRONZE = .04, BASE = 1200;
int membership =0;
double year =0;
do {
cout << " Welcome to Ronada's Strikeforce Gym!! " << endl;
cout << "x------------------------------------x" << endl;
cout << " Membership Fee Calculator " << endl;
cout << "1. Gold " << endl;
cout << "2. Silver " << endl;
cout << "3. Bronze " << endl;
cout << "4. Quit " << endl << endl;
cout << "Please enter your membership level (1-3 Enter 4 to Quit) >" << endl;
cin >> membership;
while (membership < 1 || membership > 4)
{
cout << "Choice must be between 1 and 4" << endl;
cin >> membership;
}
cout << fixed << setprecision(2);
double memfee=BASE;
switch (membership)
{
case 1: // Gold
for (int counter = 1; counter <= 10; counter++) {
year = memfee * GOLD;
memfee += year;
cout << "Year " << counter << " $" << memfee << endl;
}
break;
case 2: // Silver
for (int counter = 1; counter <= 10; counter++) {
year = memfee * SILVER;
memfee += year;
cout << "Year " << counter << " $" << memfee << endl;
}
break;
case 3: // Bronze
for (int counter = 1; counter <=10; counter++) {
year = memfee * BRONZE;
memfee += year;
cout << "Year " << counter << " $" << memfee << endl;
}
break;
case 4: // bye-bye
cout << " Thank you for using Rhonda's Fee Calculator!";
break;
default:// Default
;// do something else
}
} while (membership != 4);
system("pause"); // see: http://www.cplusplus.com/forum/beginner/1988/
return 0;
}
|