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;
}

I compiled your code and ran it; I got this output:

Enter the number of students to be registered: 3
Enter the student number: #21
Enter the number of modules, student #21 would like to register for: 1
Enter the number of modules(from min:2 to max:5), student #21 would like to register for: 2

and it went on from there.

If I enter the first number as zero, I get what you describe:

Enter the number of students to be registered: 0
Total cost of Discounts = R 0

which would suggest you're entering the value zero.

Edited 5 Years Ago by Moschops: n/a

Nope, I entered 2 when I'm asked to enter the number of students and it goes to total cost of discounts = R 0 :(

When I enter 2, it does not. It does this.

Enter the number of students to be registered: 2
Enter the student number: #

Next guess; whatever you're running, it's not the code above. How sure are you that you've definitely compiled that code, and are running the output executable?

Edited 5 Years Ago by Moschops: n/a

Ok perfect! It works, there was a typo error, fixed now, thanks a million for your time and help :)

This article has been dead for over six months. Start a new discussion instead.