grade algorithm

I dont know if i am using a bad algorithm. the assignment is :

quizes are 25%
midterm is 25%
final is 50%
for the total grade


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
// problem 4.cpp : Defines the entry point for the console application.
//

#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int main(){
	int quizOne,quizTwo,Mid,Final,quizEnd,midEnd,finalEnd,endGrade;		//declares ints

	cout<<"Enter quiz one:"<<endl;						//enter quizOne
	cin>>quizOne;
	cout<<"Enter quiz two:"<<endl;
	cin>>quizTwo;										//enterquizTwo
	cout<<"Enter midterm"<<endl;
	cin>>Mid;											//enter mid
	cout<<"Enter Final"<<endl;
	cin>>Final;											//enter final
	

	quizEnd=(quizOne+quizTwo)*.25;					//add 2 quizes, multiply so it equals .25 out o total grade
	midEnd=Mid*.25;									//multiply so it equals .25 out of total grade
	finalEnd=Final*.5;								//multiply so it equals .5 of total grade


	endGrade=finalEnd+midEnd+quizEnd/((20*.25)+(50*.25)+(50*.5));			//algorithm to add percentages

	cout<<quizOne<<"/10"<<endl;
	cout<<quizTwo<<"/10"<<endl;								//redisplay grades
	cout<<Mid<<"/50"<<endl;
	cout<<Final<<"/50"<<endl;

	if(endGrade>=/9)										//if greater than .9 display A
	{ cout<<"A";
	}
if(endGrade>=.8,endGrade<.9)								//if greater or equal to .8 but less than .9 display b
	{ cout<<"B";
	}

if(endGrade>=.7,endGrade<.8)							//if greater or equal to .7 but less than .8 display c
	{ cout<<"C";
	}
if(endGrade>=.6,endGrade<.7)								//if greater or equal to .6 but less than .7 display d
	{ cout<<"D";
	}
if(endGrade<.6)								//if less than .6 display f
	{ cout<<"F";
	}
return 0;
}
Yes, your algrithms are wrong

1
2
3
4
5
6
7
8
9
// Find the average grade, then get 25% of that
        quizEnd=((quizOne+quizTwo)/2.0)*.25;
// You got these two right
        midEnd=Mid*.25;
        finalEnd=Final*.5;

// And you did this WAY wrong
// You are going to simply add the percents together
       endGrade=finalEnd+midEnd+quizEnd;


Here is my code that I got while working on your program
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
// problem 4.cpp : Defines the entry point for the console application.
//

#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int main(){
	int quizOne,quizTwo,Mid,Final,quizEnd,midEnd,finalEnd,endGrade;

	cout << "Enter quiz one: ";
	cin  >> quizOne;
	cout << "Enter quiz two: ";
	cin  >> quizTwo;
	cout << "Enter midterm: ";
	cin  >> Mid;
	cout <<"Enter Final: ";
	cin  >> Final;

    quizEnd=((quizOne+quizTwo)/2.0)*.25;
    midEnd=Mid*.25;
    finalEnd=Final*.5;
    endGrade=finalEnd+midEnd+quizEnd;

	cout << '\t' << quizEnd << "% of total grade" << endl;
	cout << '\t' << midEnd << "% of total grade" << endl;
	cout << '\t' << finalEnd << "% of total grade" << endl;
	cout << '\t' << endGrade << "% is your grade - ";

	if(endGrade >= 90) {
	    cout << "A" << endl;
	}
    if((endGrade >= 80) and (endGrade < 90)){
        cout << "B" << endl;
    }
    if((endGrade >= 70) and (endGrade < 80)){
        cout << "C" << endl;
    }
    if((endGrade >= 60) and (endGrade < 70)){
        cout << "D" << endl;
    }
    if(endGrade <= 60) {
        cout << "F" << endl;
    }
    system("pause");// NOTE: This is not proper coding, it is simple though
    return 0;
}
when i try the new algorithm, the end result is -B
C
D
F
The code I gave you shouldn't even compile? I forgot to include <cstdlib>, anyway it works perfectly for me?
Last edited on
I figured out why it is showing all of the other grades, because it matches the parameters of the other grades aswell, but i just want to show the 1 grade that applies to the score
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
	if(endGrade >= 38.25) {
	    cout << "A" << endl;
	
    if(endGrade >= 34,endGrade < 38.25)
        cout << "B" << endl;
    
    if(endGrade >= 29.75,endGrade < 34)
        cout << "C" << endl;
    
    if(endGrade >= 25.5,endGrade < 29.75)
        cout << "D" << endl;
    
    if(endGrade < 25.5) 
        cout << "F" << endl;
    }
You can simply put:

1
2
3
4
5
6
7
8
9
10
11
12
13
if(something)
{
cout << "grade A";
}
else if(something)
{
cout << "Grade B"; 
}
else if(something)
{
cout << "Grade C";
}
etc


Where 'something' is what you already have written. You could (and will have to where else if is not suitable) do the list correctly in the first place though:

if(endGrade >= 38.25)
{
Grade A;
}
if(endGrade < 38.25 && endGrade > 34)
{
Grade B;
}
if(endGrade < 34 && endGrade > 29.75)
{
Grade C;
}
etc
thanks i just needed the && and the braces
Topic archived. No new replies allowed.