Errors?

Hi guys im writing a program to calculate costs of a long distance tekephone call. Im getting some errors and am not sure how to fix them or what they mean for the matter. For lines 45 and 51, it says function definition not allowed. Why is that?
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
#include<iostream>
#include<string>
#include<assert.h>

using namespace std;

int starttime;
float beforediscount;
float afterdiscount;
float timediscount;
float minutesdiscount;
const float rate = 0.10;
const float costdiscount = 0.50;
const float durationdiscount = 0.15;
const float federaltax = 0.04;

int main()
{
    int starttime;
    int minutes;
    
    do
    {
        cout<< "Enter start time of call in military time: ";
        cin>> starttime;
    }
    while((starttime<0)||(starttime>2400));
    assert ((starttime<0)||(starttime>2400));
    
    cout << "Enter length of call in minutes: "<<endl;
    cin>> minutes;
    
    if((starttime<800)&&(starttime>1800))
    {
        timediscount = starttime * costdiscount;
        return(timediscount);
    }
    
    if(minutes>60)
    {
        minutesdiscount = minutes * durationdiscount;
        return(minutesdiscount);
    }
    
    float beforediscount(int starttime, const float rate, float federaltax)
    {
        beforediscount= startime * rate *federaltax;
        return(beforediscount);
    }
    
    float afterdiscount(float minutesdiscount, float timediscount, float beforediscount)
    {
        afterdiscount = beforediscount - minutesdiscount - timediscount;
        return(afterdiscount);
    }
    
    cout <<"The cost for the call is before discount is "<< beforediscount <<endl;
    cout<<"The cost for the call is after discounts is "<< afterdiscount <<endl;
    
    system("pause");
    return 0;
}
You can't define functions inside other functions. Anyway, you didn't write that code as if they were functions, so if you just comment lines 45, 46, 48, 49, 51, 52, 54, and 55, it should work.
Last edited on
Topic archived. No new replies allowed.