EDIT: Apparently, you posted your corrected version just minutes before I posted this answer. You seem to have the basic idea now, yes.
You're on the right track from where you'd been, but you still haven't quite grasped the function syntax. Specifically, you need to remove the semi-colon at the end of the function header, and put braces around the body of the function:
float calcFee (int NumSport, int NumOther)
{
float totFee;
totFee = NumSport * 120 + NumOther * 100;
return (totFee);
}
Basically, when you write a function, the form of it goes something like this:
<return-type> <function-name> ( <parameter-list> )
{
<body>;
} You always have to have the braces around the body of the function.
Here is a more or less working version of your code (some unneeded variables have been removed):
//Assignment 2 Question 4a
#include <iostream>
using namespace std;
const float feeSport = 120.00;
const float feeOther = 100.00;
const float discount = 50.00;
const float creditS = 0.75;
const float creditO = 0.50;
//Your function calcFee must be inserted here
float calcFee (int NumSport, int NumOther)
{
float totFee;
totFee = NumSport * 120 + NumOther * 100;
return (totFee);
}
int main()
{
int nrSport, nrOther;
float totFee = 0, totOther = 0;
do
{
cout << "A total number of 7 activities are allowed:-" ;
cout << endl <<endl;
cout << "Please enter the number of sport activities : " << endl;
cin >> nrSport;
cout << "Please enter the number of other activities : " << endl;
cin >> nrOther;
}
while (nrSport + nrOther > 7);
totFee = calcFee(nrSport, nrOther);
cout.setf(ios::fixed);
cout.precision(2);
cout << endl << "The monthly fee payable is : R" << totFee ;
cout << endl << endl;
return 0;
}
This will compile and run; I leave it to you to determine if it actually solves the assignment's requirements.