Hi all,
I'm taking an introduction to C++ right now and I've been scratching my head over these errors. I'm not sure why my function is not being defined?
The errors are: undefined reference to 'totalfare(char)' and [error] ID returned 1 exit status.
Not looking for straight up answers but any guidance would be most appreciated. Thanks!
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
double totalfare(char code);
void output(double);
int main()
{
string flname;
int mins, miles;
char code, surge;
double surgem, totalcost;
cout << "What is your first and last name?";
cin >> flname;
cout << "How long is your ride in minutes?";
cin >> mins;
cout << "How many miles is your ride?";
cin >> miles;
cout << "What is the code of the ride?";
cin >> code;
cout << "Is there a surge?";
cin >> surge;
if (surge == 'Y')
{
cout << "What is the surge multiplier?";
cin >> surgem;
exit(0);
}
totalcost = totalfare(code);
output(totalcost);
return 0;
}
double totalfare(char code, char surge, double surgem, int mins, int miles)
{
double totalcost;
if (code == 'X')
{
if (surge == 'Y' && totalcost >= 6.55)
{
totalcost = (surgem * 2.00) + (mins * 0.22) + (miles * 1.15);
return totalcost;
}
else
{
totalcost = 6.55;
return totalcost;
}
}
else if (code == 'S')
{
if (surge == 'Y' && totalcost >= 25.00)
{
totalcost = (surgem * 15.00) + (mins * 0.90) + (miles * 3.75);
return totalcost;
}
else
{
totalcost = 25.00;
return totalcost;
}
}
else if (code == 'L')
{
if (surge == 'Y' && totalcost >= 10.55)
{
totalcost = (surgem * 5.00) + (mins * 0.50) + (miles * 2.75);
return totalcost;
}
else
{
totalcost = 10.55;
return totalcost;
}
}
}
void output(double totalcost)
{
cout << "Your total cost is: " << totalcost << endl;
return;
}