Need help getting this to program to execute (and work)

I am working on a program for one of my college classes. The exercise requires us to rewrite a program we did in an earlier chapter but using user-defined functions. The program is used to calculate a cell phone bill based off of the type of service (regular or premium) and there are different equations for each. Here is what I have, it refuses to work and my IDE will not show me where the error occurs so I could really use some help. Any help is appreciated. Thanks a lot!

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
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;

double bill(double numUsedPremDay, double numUsedPremNight, double dayCharges,
        double nightCharges, double totalPremCharges, double totalPremMinUsed,
         double numUsedReg, double charges);




        
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 << "Enter the service code(r (or R)  means regular and p or (P) means premium):";
    cin >> servCode;
    cout << endl;
      
    cout << "Account Number: " << accNum << endl;
    cout << "Type of service: " << servCode << endl;
    cout << "Amount due:$" << bill(numUsedPremDay, numUsedPremNight, dayCharges,
         nightCharges,  totalPremCharges,  totalPremMinUsed,
         numUsedReg, charges) << endl;      
   
   
return 0;        
}
   
double bill(double numUsedPremDay, double numUsedPremNight, double dayCharges,
        double nightCharges, double totalPremCharges, double totalPremMinUsed,
         double numUsedReg, double charges, int accNum, char servCode){
    
    
        
        
        
        
        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 
    {
       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);
        totalPremMinUsed = numUsedPremDay + numUsedPremNight;
        
        
        
    }  
         
    }
on line 69: you don't have a end curly brace. instead you have a open curly brace on line 82 instead of the end curly brace.
on lines 82 & 86: you have an out of place curly brace block. This cause the curly brace block to fail as it doesn't have anything to work with.
other than that it looks like it will run.

I hope this helps.

- Hirokachi
Still did not work. I was messing around trying to find the issue and I removed the code from lines 34-39 and the program runs, but it closes after entering the service code, so Im thinking that the error has something to do with those lines, and I also have an error with the function running it seems. It makes no sense, I wrote another program using a user-defined function and it worked, I followed the same layout in this one and it does not want to work.
Fixing the errors and warnings in your code would go a long way to getting the program to run.

In function 'double bill(double, double, double, double, double, double, double, double, int, char)':
53:34: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
45:62: warning: parameter 'totalPremMinUsed' set but not used [-Wunused-but-set-parameter]
At global scope:
45:37: warning: unused parameter 'totalPremCharges' [-Wunused-parameter]
46:36: warning: unused parameter 'charges' [-Wunused-parameter]
46:49: warning: unused parameter 'accNum' [-Wunused-parameter]
In function 'int main()':
38:29: warning: 'numUsedPremDay' is used uninitialized in this function [-Wuninitialized]
38:29: warning: 'numUsedPremNight' is used uninitialized in this function [-Wuninitialized]
38:29: warning: 'dayCharges' is used uninitialized in this function [-Wuninitialized]
38:29: warning: 'nightCharges' is used uninitialized in this function [-Wuninitialized]
38:29: warning: 'totalPremCharges' is used uninitialized in this function [-Wuninitialized]
38:29: warning: 'totalPremMinUsed' is used uninitialized in this function [-Wuninitialized]
38:29: warning: 'numUsedReg' is used uninitialized in this function [-Wuninitialized]
38:29: warning: 'charges' is used uninitialized in this function [-Wuninitialized]
/tmp/ccxtnR1m.o: In function `main':
:(.text.startup+0xcd): undefined reference to `bill(double, double, double, double, double, double, double, double)'
collect2: error: ld returned 1 exit status

The above is from the C++ Shell on line compiler (The gear symbol to the right of your code).
Topic archived. No new replies allowed.