Need help with getting the if else statement to work properly

I am writing a program that takes the service code (either 'R' for regular or 'P' for premium)and calculates a cell phone bill. I am having a problem getting the program to work right. When you enter a 'P' or 'p' it still calculates as if you had entered 'r'. If any of you can see what I have done wrong, I'd sure appreciate it. Thanks.
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
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;
double bill(char servCode);




        
int main() 

{
    int accNum;
    double numUsedReg, numUsedPremDay, numUsedPremNight, charges, dayCharges,
            nightCharges, totalPremCharges, totalPremMinUsed;
    char servCode;
   
    cout << "Enter the account number: ";
    cin >> accNum;
    cout << endl;
    
    
   
    
   
     cout << "Your bill is:$ " << bill (servCode) << endl;
}
   
   
       

   
double bill(char servCode)

{
    
    double numUsedReg, numUsedPremDay, numUsedPremNight, charges, dayCharges,
            nightCharges, totalPremCharges, totalPremMinUsed;
    
    cout << "Enter the service code(r (or R)  means regular and p or (P) means premium):";
    cin >> servCode;
    cout << endl;
    
        if (servCode = 'r' or 'R')
    {
        cout << "Enter the number of minutes that were used: ";
        cin >> numUsedReg;
        cout << endl;
        if (numUsedReg >= 50)
            return 10 + ((numUsedReg - 50) * .20);
        
        else 
            return 10;
            cout << fixed << setprecision (2);
       
        
    }
    
        else if (servCode = 'p' or 'P')
        {
       cout << "Enter the number of minutes used during the day: ";
        cin >> numUsedPremDay;
        cout << endl ;         
       
        cout << "Enter the number of minutes used at night: ";
        cin >> numUsedPremNight;
        cout << endl;
    
      
            
        if (numUsedPremDay >= 75)
            dayCharges = (numUsedPremDay - 75) * .10;
        else dayCharges = 0;
        
    
        if (numUsedPremNight >= 100)
            nightCharges = (numUsedPremNight - 100) * .05;
        else nightCharges = 0;
       
        
       return 25 + (dayCharges + nightCharges);
       
        
        }  
        
    }
There are a few problems with your if statement.

1. You need to use == for comparisons, not = which is assignment.

2. "or" does not work like that (I'm not to sure it works at all, although I may be wrong). The proper way to use or is (Boolean statement) or (Boolean statement). So, to do yours, it would be (servCode == 'p' || servCode == 'P'), with ||, the "or" operator.
Last edited on
http://www.cplusplus.com/doc/tutorial/operators/ Has information on these operators.
Thanks for the help! Both were simple things, and things I knew, but for some reason forgot about them and just overlooked it. Works fine now.
Topic archived. No new replies allowed.