program help please

program that the relevant data, such as the student number, number of modules and the module codes. the program should validate the number of modules that a student is allowed to register for and calculate the student fees plus the discounts awarded for each student. thereafter an invoice should be displayed. this invoice should indicate the student number, number of modules the student is registering for, total registration fees (after deducting the discount), and the discount awarded. the program should also calculate and display the total value of discounts awarded to all the students.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
 
#include <iostream>
using namespace std;

int main()
{
    int numStudents, studentNumber, numModules, moduleCode;
    const int leastNumOfModules = 2, highestNumberOfModules = 5;
    const float superDiscount = 0.3, highDiscount = 0.2, midDiscount = 0.1, lowDiscount = 0.02;
    float totalFees = 0, totalDiscount = 0, studentFees = 0, studentDiscount;
    
    //prompt for number of students
    
    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;
        
        
    //valadate number of modules
        
        while ((numModules < 2) || (numModules > 5) )
        {
            cout << "invalid number of modules, please enter again: " << endl;
            cin >> numModules;
        }
        
    //this for loop handles all the modules for a specific student
        
        for (int j = 1; j <= 5 ; ++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" << endl;
            }//end of switch statement
       
         }//end of inner loop
        
        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;
        }
        
        //calculate student fees
        studentFees = studentFees - studentDiscount;
        
        //calculate total discount awarded
        totalDiscount += studentDiscount;
        
        cout.setf(ios::fixed);
        cout.precision(2);
        
        cout << "......REGISTRATION FEES INVOICE......" << endl;
        
        cout << " student number : # ";
        cout.width(10);
        cout << studentNumber << endl;
        
        cout <<"Number of modules : # ";
        cout.width(10);
        cout << numModules << endl;
        
        cout <<"Totalfees : R ";
        cout.width(10);
        cout << totalFees << endl;
        
        cout << "Discount : R ";
        cout.width(10);
        cout << studentDiscount;
        
        cout <<"No discount awarded" << endl;
        
        //reset studentFees to 0 for next student
        studentFees = 0;
        
    }//end of outer loop
    
    cout <<"total cost of discount = R" << totalDiscount << endl;
    
}
Last edited on
What is your question?

Line 109: This is going to be displayed whether a discount was calculated or not.

Line 112: Setting studentFees to 0 here works only because you don't have any break statements in your loop. A break statement would cause this statement to be skipped. It's better style to set studentFees to 0 at the top of the loop then you don't have to worry that the code stops working if you add a break statement at some point in the future.



Last edited on
i am struggling to calculate totalfees and display it....
also the discounted amount and the total discount to be displayed.
You never increment totalFees anywhere. Not clear if totalFees is per student, or an overall total. I'm assuming an overall total, since studentFees represents per student fees.

I would change lines 101-103 as follows:
101
102
103
104
        cout <<"Studentfees : R ";
        cout.width(10);
        cout << studentFees << endl;  // Fees for this student
        totalFees += studentFees;  // Accumulate total fees. 


Then at the end:
115
116
117
      cout <<"Totalfees : R ";
        cout.width(10);
        cout << totalFees << endl;


totalDiscount looks as if it should be working.
Last edited on
okay, nut my this is why is it not pulling totalfee from how i wrote it?

if i sun the program i get my discount but i dont get the total discount for all students.
because it displays my student discount fine.
okay, nut my this is why is it not pulling totalfee from how i wrote it?

As I said before, you never increment totalFees, so why would it display anything other than 0?
ok fixed the totalFees.

now how do i get it to display the totalDisccount for all students
You increment totalDiscount at line 86 and display it at line 116.
That all looks fine.

Is the console window closing before you can see totalDiscount?
If so, add after line 116:
 
  system ("pause");


If that's not the problem, please post your current code.

Topic archived. No new replies allowed.