can someone make this code work?

#include <cstdlib>
#include <iostream>
#include <iomanip>

using namespace std;

double getDistance();
int getPassengerCount();
double calculateFare (double &distance, int &count, double &total);

const double rate = 2.40;
const double surcharge = 1.20;

int main(int argc, char *argv[])
{
double distance = 0;
int count = 0;


cout<<"Enter distance traveled: ";
cin>>distance;


cout<<"Enter number of passengers: ";
cin>> count;


calculateFare(distance , count , total);

cout<< "It will cost $"<<total<< " for " << count <<
" passenger(s) to travel "<< distance << "miles in my taxi."<<endl;


system("PAUSE");
return EXIT_SUCCESS;
}
double calculateFare(double d, int c, double t)
{
const double rate = 2.40;
const double surcharge = 1.20;

if (count = 1)
{
t = d * rate;
}
else
{
t= (d * rate) + (surcharge * count);
}
}
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
#include <cstdlib>
#include <iostream>
#include <iomanip>

using namespace std;

double getDistance();
int getPassengerCount();
float calculateFare (double distance, int count);//changed to float because it's better for money value

const double rate = 2.40;
const double surcharge = 1.20;

int main(int argc, char *argv[])
{
double distance = 0;
int count = 0;
float total = 0;//added a total variable


cout<<"Enter distance traveled: ";
cin>>distance;


cout<<"Enter number of passengers: ";
cin>> count;


total=calculateFare(distance , count);//made it so a variable total is equal to an outcome of function calculateFare


cout<< "It will cost $"<<total<< " for " << count << 
" passenger(s) to travel "<< distance << "miles in my taxi."<<endl;


system("PAUSE");
return EXIT_SUCCESS;
}
float calculateFare(double d, int c)
{
const double rate = 2.40;
const double surcharge = 1.20;
float t;
if (c = 1)
{
t = d * rate;
}
else
{
t= (d * rate) + (surcharge * c);
}
return t;//made it so fucntion returns the t variable
}
Last edited on
it worked beautifuly on my compiler, my compiler has been more forgiving though, whats wrong with it??
thanks!
Topic archived. No new replies allowed.