Tuition Calculator // do-while Loop and a switch Statement

Hi,
I am running into a bit of a brick road with my output...

As far as I can tell my code is accurate and I am getting no errors

Below is my coding

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
#include <iostream>
using namespace std;

int main()
{
   char calc, parking, sticker, idcard;
   int credits, resident, semester;
   const double fs_parking = 85.00, ws_parking = 45.00,
	   fs_service = 50.50, ws_service = 47.50, 
	   as_sticker = 19.50, id_card = 13.00;
   double fee;

   do
   {
	 cout << "Enter number of units enrolled:";
     cin >> credits;
     cout << "Is this Fall[0], Winter[1], Spring[2] or Summer[3] session:";
     cin >> semester;
	 cout << "Are you a state resident[0] or not[1]:";
     cin >> resident;

     switch(resident)
     {
        case '0':   fee = credits * 46.00;
                    break;

        case '1':   fee = credits * 295.00;
                    break;

        default:    cout << "You must enter 0, or 1\n";

      } // end switch 

	 cout << "Want a parking decal? [y/n]:";
     cin >> parking;
	      
	 switch(parking)
     {
        case 'y':
		case 'Y':	
			if (semester = 0, 2) 
				fee = fee + fs_parking;
			else
				fee = fee + ws_parking;
                    break;

        case 'n':
		case 'N': fee = fee;
                    break;

        default:    cout << "You must enter Y, or N\n";

      } // end switch 

     cout << "Want an AS sticker? [y/n]:";
     cin >> sticker;
	 	 switch(parking)
     {
        case 'y':
		case 'Y': fee = fee + as_sticker;

        case 'n':
		case 'N': fee = fee;
                    break;

        default:    cout << "You must enter Y, or N\n";

      } // end switch 
	 cout << "Want an ID card? [y/n]:";
     cin >> idcard;
	 	 switch(parking)
     {
        case 'y':
		case 'Y': fee = fee + id_card;
				break;
        case 'n':
		case 'N': fee = fee;
                    break;

        default:    cout << "You must enter Y, or N\n";

      } // end switch 
         
	if (semester = 0)
	{
		cout << "For Fall semester, your total fees are" << fee + fs_service;
	}
	else if (semester = 1)
	{
		cout << "For Winter semester, your total fees are" << fee + ws_service;
	}
	else if(semester = 2)
	{
		cout << "For Spring semester, your total fees are" << fee + fs_service;
		}
	else if(semester = 3)
	{
		cout << "For Summer semester, your total fees are" << fee + ws_service;
		}

	cout << "\nWould you like to do another calculation? Y or N: ";
     cin >> calc;      

   } while( calc=='y' || calc=='Y' ); 

   return 0;
}



and below is the output I get

It seems to have it's first error at "Are you a state resident"


Enter number of units enrolled:18
Is this Fall[0], Winter[1], Spring[2] or Summer[3] session:0
Are you a state resident[0] or not[1]:0
You must enter 0, or 1
Want a parking decal? [y/n]:n
Want an AS sticker? [y/n]:n
Want an ID card? [y/n]:n
For Winter semester, your total fees are-9.25596e+061
Would you like to do another calculation? Y or N: n
Press any key to continue . . .



For reference the instructions for the assignment are as follows


SANTA MONICA COLLEGE STUDENT FEES (as of Fall, 2012)

Enrollment Fee

$ 46.00/ unit for California Residents
$ 295.00/ unit for F1/Non-Residents

Student Services Fee
(AS Sticker fee is Optional, saving $19.50)
(ID Card fee is Optional, saving $13)

$ 47.50 Winter/Summer
$ 50.50 Fall/Spring

Parking Decal (Optional)

$ 45.00 Winter/Summer
$ 85.00 Fall/Spring

A number of different program dialogues describe the program I am looking for.

SMC Fee Calculator
Enter number of units enrolled: 18
Is this Fall[0], Winter[1], Spring[2] or Summer[3] session: 0
Are you a state resident[0] or not[1]: 0
Want a parking decal? [y/n]: n
Want an AS sticker? [y/n]: n
Want an ID card? [y/n]: n
For Fall semester, your total fees are $ 846.00
closed account (18hRX9L8)
Change resident type to char or change your case to int. (int)'0' is not the same thing as (int)0. See ASCII table if you want to convert characters to ints. http://www.cplusplus.com/doc/ascii/
Last edited on
Great,
I was able to get it to a point where it "works"
But it seems the math is off--
I went to a calculator and it seems that it should add up correctly, but some of the totals are off

I also notice that the last line, "For X Semester, your total fees..."
always says winter... which probably lies the problem...
Not sure really how to go about correcting this..

Here is my code and output

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
#include <iostream>
using namespace std;

int main()
{
   char calc, parking, sticker, idcard, resident;
   int credits, semester;
   const double fs_parking = 85.00, ws_parking = 45.00,
	   fs_service = 50.50, ws_service = 47.50, 
	   as_sticker = 19.50, id_card = 13.00, resident_fee = 46.00, nonresident_fee = 295.00;
   double fee;

   do
   {
	 cout << "Enter number of units enrolled:";
     cin >> credits;
     cout << "Is this Fall[0], Winter[1], Spring[2] or Summer[3] session:";
     cin >> semester;
	 cout << "Are you a state resident[0] or not[1]:";
     cin >> resident;

     switch(resident)
     {
        case '0':   fee = credits * resident_fee;
                    break;

        case '1':   fee = credits * nonresident_fee;
                    break;

        default:    cout << "You must enter 0, or 1\n";

      } // end switch 

	 cout << "Want a parking decal? [y/n]:";
     cin >> parking;
	      
	 switch(parking)
     {
        case 'y':
		case 'Y':	
			if (semester = 0, 2)
			{
				fee = fee + fs_parking;
			}
			else if (semester = 1, 3)
			{
				fee = fee + ws_parking;
			}
                    break;

        case 'n':
		case 'N': fee = fee;
                    break;

        default:    cout << "You must enter Y, or N\n";

      } // end switch 

     cout << "Want an AS sticker? [y/n]:";
     cin >> sticker;
	 	 switch(sticker)
     {
        case 'y':
		case 'Y': fee = fee ;

        case 'n':
		case 'N': fee = fee - as_sticker;
                    break;

        default:    cout << "You must enter Y, or N\n";

      } // end switch 
	 cout << "Want an ID card? [y/n]:";
     cin >> idcard;
	 	 switch(idcard)
     {
        case 'y':
		case 'Y': fee = fee;
				break;
        case 'n':
		case 'N': fee = fee - id_card;
                    break;

        default:    cout << "You must enter Y, or N\n";

      } // end switch 
         
	if (semester = 0)
	{
		cout << "For Fall semester, your total fees are $ " << fee + fs_service;
	}
	else if (semester = 1)
	{
		cout << "For Winter semester, your total fees are $ " << fee + ws_service;
	}
	else if(semester = 2)
	{
		cout << "For Spring semester, your total fees are $ " << fee + fs_service;
		}
	else if(semester = 3)
	{
		cout << "For Summer semester, your total fees are $ " << fee + ws_service;
		}

	cout << "\nWould you like to do another calculation? Y or N: ";
     cin >> calc;      

   } while( calc=='y' || calc=='Y' ); 

   return 0;
}


'\\psf\home\documents\visual studio 2010\Projects\Tuition\Tuition'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
Enter number of units enrolled:18
Is this Fall[0], Winter[1], Spring[2] or Summer[3] session:0
Are you a state resident[0] or not[1]:0
Want a parking decal? [y/n]:n
Want an AS sticker? [y/n]:n
Want an ID card? [y/n]:n
For Winter semester, your total fees are $ 843
Would you like to do another calculation? Y or N: y
Enter number of units enrolled:6
Is this Fall[0], Winter[1], Spring[2] or Summer[3] session:1
Are you a state resident[0] or not[1]:1
Want a parking decal? [y/n]:y
Want an AS sticker? [y/n]:y
Want an ID card? [y/n]:y
For Winter semester, your total fees are $ 1883
Would you like to do another calculation? Y or N: y
Enter number of units enrolled:18
Is this Fall[0], Winter[1], Spring[2] or Summer[3] session:2
Are you a state resident[0] or not[1]:1
Want a parking decal? [y/n]:y
Want an AS sticker? [y/n]:y
Want an ID card? [y/n]:y
For Winter semester, your total fees are $ 5423
Would you like to do another calculation? Y or N:



And this is what the output SHOULD be

SMC Fee Calculator
Enter number of units enrolled: 18
Is this Fall[0], Winter[1], Spring[2] or Summer[3] session: 0
Are you a state resident[0] or not[1]: 0
Want a parking decal? [y/n]: n
Want an AS sticker? [y/n]: n
Want an ID card? [y/n]: n
For Fall semester, your total fees are $ 846.00

SMC Fee Calculator
Enter number of units enrolled: 6
Is this Fall[0], Winter[1], Spring[2] or Summer[3] session: 1
Are you a state resident[0] or not[1]: 1
Want a parking decal? [y/n]: y
Want an AS sticker? [y/n]: y
Want an ID card? [y/n]: y
For Winter semester, your total fees are $ 1862.50

SMC Fee Calculator
Enter number of units enrolled: 18
Is this Fall[0], Winter[1], Spring[2] or Summer[3] session: 2
Are you a state resident[0] or not[1]: 1
Want a parking decal? [y/n]: y
Want an AS sticker? [y/n]: y
Want an ID card? [y/n]: y
For Winter semester, your total fees are $ 5445.50

closed account (18hRX9L8)
To skip a line use std::endl or "\n".
Topic archived. No new replies allowed.