The code runs but the problem is that the the discount value is not calculated wrong.
Which part did I miss here.
Here is the question:
You now have to add a function discFee that has three value parameters - two of type int representing the
number of sport and other activities, and one of type float representing the monthly fee before discount. The
function returns the discounted fee of type float. Remember that the discount differs depending the number of
activities. You also have to add the function calcCredit that has two value parameters of type int, representing
the number of sport and other activities respectively. The function calculates the number of credits obtained in a
variable of type float. We give the changed main function below. Test your program with these input values, but
do not submit any printouts.
//Assignment 2 Question 4b
#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);}
// your function discFee must be inserted here
float discFee (int numSport, int numOther, float monthFee){
int newFee;
if ((numSport + numOther == 4 )|| (numSport + numOther == 5)){
float newFee;
float Disc = 75.00;
monthFee = (feeSport * numSport) + (feeOther * numOther);
newFee = monthFee - Disc;
}
if ((numSport + numOther == 6 )|| (numSport + numOther == 7)){
float newFee;
float Disc = 125.00;
monthFee = (feeSport * numSport) + (feeOther * numOther);
newFee = monthFee - Disc;
}
return (newFee);
}
// your function calcCredit must be inserted here
float calcCredit (int numSport, int numOther){
float credit;
credit = (numSport * creditS) + (numOther * creditO);
return (credit);
}
int main()
{
int nrSport, nrOther;
float totFee = 0, newFee = 0, credits = 0, totSport = 0, totOther = 0;
do
{
cout << "A total number of 7 activities are allowed:-" << 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;
newFee = discFee(nrSport, nrOther, totFee);
cout << endl << "The discounted fee is : R" << newFee ;
cout << endl << endl;
credits = calcCredit(nrSport, nrOther);
cout << endl << "The credits obtained : " << credits ;
cout << endl << endl;
return 0;
}