using functions

Im getting this error when i try to run this program . "92 error a function-definition is not allowed here before token " and on line 118 " error expected'}' at the end of input . I cant figure out what that means
tried removing those brackets but it actually gives more errors

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
112
113
114
115
116
117
118
#include <iostream>
#include <iomanip>
using namespace std;

void regularBill (string accountNumberP, char serviceP ,int minutesP,float billingAmountP)
{
   cout<< "How many minutes were used? ";
   cin >> minutesP;
   if (minutesP <= 50.00)
   {
       billingAmountP = 100.00;
      cout<< "Amount due: R" << billingAmountP << endl;
      cout<< "Account number: "<< accountNumberP <<endl;
      cout<< "Service type: "<< serviceP << endl;
      cout<< "Minutes used: "<< minutesP <<endl;

   }

   else
   {
       billingAmountP = ((minutesP -50.00) * 0.99);
      cout<< "Amount due: R" << billingAmountP << endl;
      cout<< "Account number: " << accountNumberP <<endl;
      cout<< "Service type: " << serviceP << endl;
      cout<< "Minutes used: " << minutesP <<endl;

   cout .setf(ios::fixed);
   cout.precision(2);


   }

}


void premiumBill (string accountNumber0,char service0 ,int minutes1, int minutes2 ,float billingAmount0,float day_min, float night_min)
{

          cout<< "How many minutes were used during the day? ";
          cin >> day_min;
          cout<< "How many minutes were used during the night? ";
          cin >> night_min;


  if (day_min <= 75)


{
      billingAmount0 = 250.00;

      cout<< "Amount due: R" << billingAmount0 << endl;
      cout<< "Account number: "<< accountNumber0 <<endl;
      cout<< "Service type: "<< service0 << endl;
      cout<< "Minutes used: "<< day_min <<endl;

}
   else if (day_min > 75)
     {
      billingAmount0 = ((day_min - 75) * 0.49)+ 250.00;
      cout<< "Amount due: R" << billingAmount0 << endl;
      cout<< "Account number: "<< accountNumber0 <<endl;
      cout<< "Service type: "<< service0 << endl;
      cout<< "Minutes used: "<< day_min <<endl;
     }

   else if (night_min <= 100)
     {

      billingAmount0 = 250.00;
      cout<< "Amount due: R" << billingAmount0 << endl;
      cout<< "Account number: "<< accountNumber0 <<endl;
      cout<< "Service type: "<< service0 << endl;
      cout<< "Minutes used: "<< day_min <<endl;

     }

   else if (night_min > 100)
     {
      billingAmount0 = ((day_min - 100) * 0.29)+ 250.00;
      cout<< "Amount due: R" << billingAmount0 << endl;
      cout<< "Account number: "<< accountNumber0 <<endl;
      cout<< "Service type: "<< service0 << endl;
      cout<< "Minutes used: "<< day_min <<endl;
     }
      cout .setf(ios::fixed);
      cout.precision(2);

 return;


   int main()
{



int account_number;
float minutes;
char service;
float billingAmount;
float regularBill();
float premiumBill()

   cout << "Please enter your account number: " ;
   cin  >> account_number;
   cout << "Do you have Regular service or Premium service (r or p)? ";
   cin >> service;

   if (service == 'r' || service =='R')
      regularBill();
   else if (service == 'p' || service =='P')
      premiumBill();
   else
   {
      cout<< "Wrong input, program terminated!" << endl;
      return ;
   }

}
Last edited on
line 89 you need a closing bracket
thank you , now having error with line 110 , and 112 . undefined reference to regulaBill and premiumBill . i think there is a problem with how i called the functions.
line 101 you forgot a ; also you are passing any arguments
ok i fixed that , im not sure though how to pass the arguments , im stuck
You wrote the program but do not know how to pass the argument? interesting... Anyways, lets look at the first part
1
2
if (service == 'r' || service =='R')
      regularBill();
if you call regularBill() you will get an error because your function at the top is defined as : void regularBill (string accountNumberP, char serviceP ,int minutesP,float billingAmountP) which takes 4 arguments. Also, you may want to incorporate a switch statement block instead of if/ else-if statements incase you want to expand your program later.
Topic archived. No new replies allowed.