This is the program that I have written, my problem is that the contents in the for loop does not execute. When I compile I get enter number of students to be registered
And total cost of discount is R 0
QUESTION 2
PROGRAM
#include <iostream>using namespace std;
int main()
{
int numStudents;
int studentNumber;
int numModules;
int moduleCode;
const int leastNumOfModules = 2;
const int highestNumOfModules = 5;
const float superDiscount = 0.3;
const float highDiscount = 0.2;
const float midDiscount = 0.1;
const float lowDiscount = 0.02;
float totalFees = 0;
float totalDiscount = 0;
float studentFees = 0;
float studentDiscount;
cout << "Enter the number of students to be registered: ";
cin >> numStudents;
for(int i = 0; i < numStudents; i++)
{
cout << "Enter the student number: #" ;
cin >> studentNumber;
cout<< "Enter the number of modules, student #" <<studentNumber
<< " would like to register for: " ;
cin >> numModules;
while((leastNumOfModules > numModules) || (highestNumOfModules < numModules))
{
cout<< "Enter the number of modules(from min:2 to max:5), student #" <<studentNumber
<< " would like to register for: " ;
cin >> numModules;
}
for(int j=0 ; j < numModules ; j++)
{
cout<< "Enter course code for module " << j+1 << " : ";
cin >> moduleCode;
switch (moduleCode)
{
case 101 :
case 102 :
case 103 :
case 104 :
case 105 : studentFees = studentFees + 500.00;
break;
case 201 :
case 202 :
case 203 : studentFees = studentFees + 1000.00;
break;
case 301 :
case 302 :
case 303 : studentFees = studentFees + 2000.00;
break;
default : cout << "Incorrect module code entered";
j--;
}
}
if (studentFees >= 5000.00 && numModules >= 5)
{
studentDiscount = superDiscount*studentFees;
}
else if (studentFees < 5000.00 && studentFees >= 3000.00 && numModules >= 4)
{
studentDiscount = highDiscount*studentFees;
}
else if (studentFees < 3000.00 && studentFees >= 2000.00 && numModules >= 3)
{
studentDiscount = midDiscount*studentFees;
}
else if (studentFees < 2000.00 && numModules >= 2)
{
studentDiscount = lowDiscount*studentFees;
}
else
{
studentDiscount = 0;
}
studentFees = studentFees - studentDiscount;
totalDiscount = totalDiscount+studentDiscount ;
cout.setf(ios::fixed);
cout.precision(2);
int numStudents;
int studentNumber;
int numModules;
int moduleCode;
cout<<"...........REGISTRATION FEES INVOICE............" << endl;
cout<<"Student Number : # ";
cout.width(10);
cout<< numStudents << endl;
cout<<"Number of modules : # ";
cout.width(10);
cout<< numModules << endl;
cout<<"Total Fees : R ";
cout.width(10);
cout<< studentFees << endl;
cout<<"Discount : R ";
cout.width(10);
cout<< studentDiscount << endl;
cout<<"................................................" << endl;
studentFees = 0;
}
cout << "Total cost of Discounts = R " << totalDiscount << endl;
}