there are a few errors:
Code:
if (insemester == 'F' || 'S')
can't be done, look at my if(buffer[0]...) for comparison.
Code:
fsws = true;
double student_services_cost(bool fsws);
this isn't allowed, this is the predefinition of the function, when calling it, you need to do it like:
Code:
my_variabel = student_services_cost(fsws);
here's my lil' version in strickt ANSI C++
Code:
#include <iostream>
#include <iomanip>
using namespace std;
//--
const double FALLSPRING_COST = 30.00;
const double WINTERSUMMER_COST = 27.00;
const double PARK_FALLSPRING_COST = 75.00;
const double PARK_WINTERSUMMER_COST = 35.00;
const double ENROLL_CALI = 26.00;
const double ENROLL_US = 149.00;
const double ENROLL_VISA = 171.00;
const double REFUND_FALLSPRING = 10.00;
const double REFUND_WINTERSUMMER = 9.00;
//--
//fsws true = FALLSPRING COST, false is WINTERSUMMER.
double student_services_cost(bool fsws);
double parking_cost(bool fsws);
double student_sticker_refund(bool fsws);
//r: 'c' = california, 'u' = US residents, 'v' = visa holders;
double enrollment_cost(char r);
int main()
{
bool fsws;
double total = 0;
char input, enrol = '\0';
int count, units = 0;
cout << "Student Fee Calculator:" << endl;
/* first the question is winter/fall/spring/summer */
cout << "What semester am I calculating fees for?" << endl;
cout << "\t[F]all" << endl;
cout << "\t[W]inter" << endl;
cout << "\t[S]pring" << endl;
cout << "\tsu[M]mer" << endl;
cout << "\t\t:";
cout.flush();
cin >> input;
switch(input)
{
case 'f':
case 'F':
case 's':
case 'S':
fsws = true;
break;
case 'm':
case 'M':
case 'w':
case 'W':
fsws = false;
break;
default:
cout << "Error reading semester from stdin" << endl;
return -1;
}
/* next question can be uptimised we
* can repeat the same steps several times
*/
for(count = 0; count <= 4; count++)
{
if(!count) /* first time CA question */
cout << "Are you a California resident? [y/n]";
if(count == 1)/* second time US question */
cout << "Are you a US citizen? [y/n]";
if(count == 2)/* last time visa question */
cout << "Are you an F1 visa holder? [y/n]";
if(count == 3)
cout << "Do you need parking sticker? [y/n]";
if(count == 4)
cout << "Are you requesting an AS sticker refund? [y/n]";
cout << endl;
cout << "\t\t: ";
cout.flush();
cin >> input;
if(input == 'y' || input == 'Y')
{
if(!count)
{
enrol = 'c';
/* jump to parking question */
count = 2;
continue;
}
if(count == 1)
{
enrol = 'u';
/* jump to parking question */
count = 2;
continue;
}
if(count == 2)
enrol = 'v';
if(count == 3)
total += parking_cost(fsws);
if(count == 4)
total -= student_sticker_refund(fsws);
}
}
if(!enrol)
{
cout << "Error getting sitizens" << endl;
return -1;
}
cout << "How many units will you enrol in?" << endl;
cout << "\t\t: ";
cout.flush();
cin >> units;
total += units * enrollment_cost(enrol);
total += student_services_cost(fsws);
cout << "Total cost for student fee:"<< endl;
cout << "\tUnits:\t" << units << endl;
cout << "\tCost:\t";
cout << setprecision(2) << setiosflags(ios::fixed);
cout << total << endl;
return 0;
}
//----------------------------------------------
double student_services_cost(bool fsws)
{
if(fsws == true)
{
return FALLSPRING_COST;
}
return WINTERSUMMER_COST;
}
//----------------------------------------------
double parking_cost(bool fsws)
{
if(fsws == true)
{
return PARK_FALLSPRING_COST;
}
return PARK_WINTERSUMMER_COST;
}
//----------------------------------------------
double student_sticker_refund(bool fsws)
{
if(fsws == true)
{
return REFUND_FALLSPRING;
}
return REFUND_WINTERSUMMER;
}
//----------------------------------------------
double enrollment_cost(char r)
{
switch(r)
{
case 'c':
return ENROLL_CALI;
case 'u':
return ENROLL_US;
case 'v':
return ENROLL_VISA;
default:
return 0;
}
}
Note this is not to be taken as a version I've made for your convenience, you can take a look at my way of handling the user interaction and see if that makes any sence..
Then try and see if you can come up with some clever way of handling it, while taking peeks at my code.
Now this diverts a bit from the orriginal description, which stated there should be functions taking call by value and call by reference, this does not have function calls, which takes call by reference.
But that can be achieved by moving the user interaction into a function by itself, which will take the total as an argument, and fill it with the total value, while returning an int or something simular. This is however left as an exercise for the reader.