Calculation problem


The calculation keeps coming out messed up... Can someone please explain to me what I am doing wrong..

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
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
int pro, 
    maxpro,
    maxtext, 
    quiz, 
    quizpoints,
    quiztotal, 
    lowquizscore; 
    
double maxtest = 0.00,
       test = 0.00,
       proavg = 0.00, 
       quizavg = 0.00, 
       overalltestquiz = 0.00, 
       courseavg = 0.00;

cout << fixed << showpoint << setprecision (2);


   

      
      cout << "Enter the total program points that have been earned: ";
      cin >> pro;
     
      cout << "\nEnter the maximum number of program points available: ";
      cin >> maxpro;
      
 
     
for (quiz = 0; quiz < 10; quiz++);
      {
      cout << "Enter the total quiz points that have been earned ";
      cin >> quiztotal;
      
      cout << "\nEnter the number of quizzes that have been taken: ";
      cin >> quiz;
           
      cout << "\nEnter the sum of the two lowest quiz scores: ";
      cin >> lowquizscore;
      }
      cout << "\nEnter the total test points that have been earned (0 if no tests have been taken): ";
      cin >> test;
      
      cout << "\nEnter the maximum test points available: "; 
      cin >> maxtest;
      
proavg = pro / maxpro * 100;     
quizavg = (quiztotal - lowquizscore) / ((quiz - 2) * 10) * 100;
overalltestquiz = (test + quizpoints - lowquizscore) / (maxtest + ((quiz - 2) * 10)) * 100;
courseavg = (proavg * .4) + (overalltestquiz * .6);

cout << endl 
     << endl << "Course Results"
     << endl << "Program Average   " << proavg
     << endl << "Quiz Average      " << quizavg
     << endl << "Test Average      " << overalltestquiz
     << endl << "Course Average    " << courseavg << endl;

    

cout << endl;
system("pause");

return 0;
}
Last edited on
first thing u need to fix is your badly laid out post. edit it and post code your code in code tags. and use some indentation in your code for better readability.
Okay well I just figured out how to put the code tags thanks. If you can, can you tell me what I'm I doing wrong in my calculation?
This should explain it better than I could:
http://www.cplusplus.com/articles/firedraco1/

Edit: Nevermind. You seem to have figured it out yourself, but you could still use some work on the indentation. :-)
Last edited on
Which calculation, specifically? I would check over your formulas, taking care to respect order of operations and such. Also, your quiz loop only reads in a bunch of data, overwriting the previous input as it does so.
Thanks Browni I figured it out :)

Zhuge the calculation between line 54-57
The output is when I enter this numbers...
526
580
73
13
1
109
300


Course results

Program Average:   00.00
Quiz Average:      00.00
Test Average:      85.00
Course Average:    51.00



but it should look like this

Course results

Program Average:   90.69
Quiz Average:      72.00
Test Average:      45.25
Course Average:    63.43
It is probably integer division; instead of storing the input as int's, store it as a double. As it is, when you enter 526 and 580, for example, it divides 526 / 580 = 0.9069 which is truncated to 0.
Okay I have done that and it only fixed the Program Average

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
double maxtext, 
       quiz, 
       quizpoints,
       quiztotal, 
       lowquizscore,
       pro, 
       maxpro,
       maxtest = 0.00,
       test = 0.00,
       proavg = 0.00, 
       quizavg = 0.00, 
       overalltestquiz = 0.00, 
       courseavg = 0.00;



Course results

Program Average:   90.69
Quiz Average:      72.00
Test Average:      27.00
Course Average:    52.48



Now it's only the Test Average and Course Average that are coming out wrong.
You are using quizpoints when you want quiztotal in your calculation of the test & quiz average. Fixing that should fix both of them.
I see you use quizpoints on line 56 above, but where is it initialized? This will cause an error if I run it in VC++, so how are you getting any result at all?
1
2
3
4
proavg = pro / maxpro * 100;     
quizavg = (quiztotal - lowquizscore) / ((quiz - 2) * 10) * 100;
overalltestquiz = (test + quiztotal - lowquizscore) / (maxtest + ((quiz - 2) * 10)) * 100;
courseavg = (proavg * .4) + (overalltestquiz * .6);



Course results

Program Average:   90.69
Quiz Average:      65.45
Test Average:      44.15
Course Average:    62.76



That's the output when I run the program... Like it's getting closer but idk what else I am doing wrong
Your for loop looks strange. It looks like it is trying to loop ten times to record quiz information, but doesn't because it is looping on quiz, a variable you use for input inside the loop. It seems you are asking for total information so I don't even see why you have a loop in the first place.
Topic archived. No new replies allowed.