I need help with a project.

Ripoff University charges $3000 per semester for Canadian students and $10000 per semester for foreign students. In addition, dormitory fees for Canadian students are $2500 while foreign students pay $5000. Finally, in addition to this the university charges an extra $500 dollars for any student who requires a parking permit for the semester. Write a program that asks the user for their student status and if they need a parking permit.(Use a simple Y or N answer for this question) The program should then calculate the total cost for the semester and display this information to the screen

When I run it I get to the (y/n) part and it just displays both answers for no 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
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    
    int n;
    cout << "Please pick your status" << endl;
    cout << "1. Canadian" << endl;
    cout << "2. Foreign" << endl;
    cout << "3. Quit" << endl;
    cout << " " << endl;
    cin >> n;
    

    
    switch (n)
{
           
    char Choice, y, n;
    double Ans;
    
     case 1: cout << "Would you like a parking permit? (y/n)" << endl;
             
             cin >> Choice;
             if (Choice = y)
             {
             Ans = 3000 + 2500 + 500;
             cout << "Your fees are: " << Ans << "$" << endl;
             }
             else if (Choice = n);
             {
             Ans = 3000 + 2500;
             cout << "Your fees are: " << Ans << "$" << endl;
             }
             break;
     case 2: cout << "Would you like a parking permit? (y/n)" << endl;
             cin >> Choice;
             if (Choice = y)
             {
             Ans = 10000 + 5000 + 500;
             cout << "Your fees are: " << Ans << "$" << endl;
             }
             else if (Choice = n);
             {
             Ans  = 10000 + 5000;
             cout << "Your fees are: " << Ans << "$" << endl;
             }
             break;
     case 3: cout << "Goodbye!" << endl;
             break;
     default: cout << "INVALID NUMBER!" << endl;
             break;
     
}           
    system("pause");
    return 0;
}
Last edited on
char Choice, y, n; Choice, y, and n are uninitialised
cin >> Choice; choice now holds a value
if (Choice = y) y is still uninitialised
You're using the operator "=" wrong. I think you meant to use "=="

I think you meant to use if (Choice == 'y'), in which case you don't even need the variables char y, n;
Last edited on
Topic archived. No new replies allowed.