There's something wrong with this code...really ez I know

I can't find my error but I know its REALLY EASY if you have the eyes for it.
I'm having the user input 5 Grades at once
so it will calculate the Average and then assign the Letter grade to the Average.




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
// Pre-Programming Algorithm (Attempt before Code Write)
// This program will average five grades of a student, and 				assign a letter grade.
//We will set parameters on letter grades using if else 		 		statements
//After, input, it will average, then assign a letter grade


  //Step 0: Houskeeping

 # include <iostream>
 using namespace std;
int main()

 {
	
		  // Step 1: Declarations ( Grades, Average) 
		   int Grade1;
		   int Grade2;
		   int Grade3;
		   int Grade4;
		   int Grade5;
		 // (int Sum is unnecessary)
		   int Average;
	
	     // Step 2 : Request, Input Grades, & Average value ( Initialization)
		   cout << " Enter Grades with a space in between"
		   cin >> Grade1 >> Grade 2 >> Grade 3 >> Grade 4 >> Grade 5
		Grade1 = 
		Grade2 = 
		Grade3 = 
	    Grade4 = 
		Grade5 = 
		
	    Average = ;
	
		  // Step 3 : Calculate Grades ( Average )
		Average = (Grade1 + Grade2 + Grade3 + Grade4 + Grade5) / 3; \
		
		  // Step 4 : Assign Letter grades by assigning parameters using if else statements. Letters will be assigned accordingly to average calculated
		   if (Average >= 90)   //This is an “ if ” parameter (Used before “else” & “else if”)
		   cout << “A”; // This is the ouput if the above parameter is reached
		else if (Average >= 80) // If  parameter (90/A) is not reached, the statement will be skipped and its output will not be shown, program will then process this line (Line39) to decide whether true or false. If true it will output the line below (Line 40) 
		cout << “B”; // This letter will be shown if the score of 80 s reached
		else if (Average >= 70)
		cout << “C”;
		else if (Average >= 60)
		cout << “D”;
		else // If all else fails (The above parameters are not reached)
		cout < “F”; // This is the end statement for giving grades and will administer a grade of “F” if the above (Line 46) is true.
	
		
		system(“pause”);
		 return 0;
		 } // This curly bracket (Right) will signal the end of this block of code opposite of a left curly bracket (on Line 13) which signals the start.
Have you tried looking at the compiler errors?
Well there are a couple of things. Else if... don't go together. No need for pause... why do you use it? Also you didn't declare a variable... a variable is this
1
2
3
          B_score = 80,
          C_score = 70,
          D_score = 60;


You didn't give the user the option of inserting information. First you use

cout << to ask a question.

And then you use
cin >> so they can input data.

This is the code... it works.. but study it... I didn't have time to write directions, but I hope you figure it out.
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

#include <iostream>

using namespace std;

int main ()

{
	double grade1, grade2, grade3, grade4, grade5;
double score;

// get the grades

cout << "Enter the first grade: ";
cin >> grade1;

cout << "Enter the second grade: ";
cin >> grade2;


cout << "Enter the third grade: ";
cin >> grade3;
 

cout << "Enter the first grade: ";
cin >> grade4;


cout << "Enter the first grade: ";
cin >> grade5;


//calculate the average of the grades

score = (grade1 + grade2+ grade3 + grade4 + grade5) / 5.0;

//display the average
cout << " Your average is " << score <<endl;

const int A_score = 90,
          B_score = 80,
          C_score = 70,
          D_score = 60;
          
if (score >= A_score)
{
	cout << "Your garde is A. \n";
}
else
{
	if (score >= B_score)
	{
		cout << "Your grade is B. \n";
	}
	else
	{
		if (score >= C_score)
		{
			cout << "Your grade is C.\n";
		}
		else
		{
			if (score >= D_score)
			{
				cout << "Your grade is D.\n";
			}
			else
			{
				cout << "Your grade is F.\n";
			}
		}
	}
}

return 0;
}

Last edited on
> I can't find my error but I know its REALLY EASY if you have the eyes for it.

It is really easy (for any of us) if we take one small baby step at a time, and before taking the next (small baby) step, make sure that the first step is correct. The compiler will help us, all along the way.

For example:

Step 1: Declarations ( Grades )
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

int main()
{
    // Step 1: Declarations ( Grades, Average)
    int Grade1;
    int Grade2;
    int Grade 3;
    int Grade4;
    int Grade5;
}

Try to compile, link and run:
main.cpp:8:14: error: expected ';' at end of declaration
    int Grade 3;
             ^

http://coliru.stacked-crooked.com/a/647551d0b74c995f

Look at line 8, column 14 (main.cpp:8:14: error), fix the error, repeat
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

int main()
{
    // Step 1: Declarations ( Grades, Average)
    int Grade1;
    int Grade2;
    int Grade3; // *** fixed
    int Grade4;
    int Grade5;
}


Now, move on to Step 2 : Request, Input Grades
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

int main()
{
    // Step 1: Declarations ( Grades, Average)
    int Grade1;
    int Grade2;
    int Grade3;
    int Grade4;
    int Grade5;

    // Step 2 : Request, Input Grades
    std::cout << "Enter five grades with a space in between: " ;
    std::cin << Grade1 << Grade2 << Grade3 << Grade4 << Grade5 ;

    Grade3 =

    // add this line to verify that the grades have been read correctly
    // we can remove it later once we know that this part of the code is working
    std::cout << Grade1 << ' ' << Grade2 << ' ' << Grade3 << ' ' << Grade4 << ' ' << Grade5 << ' ' << '\n' ;
}

main.cpp:14:14: error: invalid operands to binary expression ('istream' (aka 'basic_istream<char>') and 'int')
    std::cin << Grade1 << Grade2 << Grade3 << Grade4 << Grade5 ;
    ~~~~~~~~ ^  ~~~~~~

http://coliru.stacked-crooked.com/a/373e4be0f6d6a200

Look at line 14, column 14 (main.cpp:14:14: error), fix the error, repeat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

int main()
{
    // Step 1: Declarations ( Grades, Average)
    int Grade1;
    int Grade2;
    int Grade3;
    int Grade4;
    int Grade5;

    // Step 2 : Request, Input Grades
    std::cout << "Enter five grades with a space in between: " ;
    std::cin >> Grade1 >> Grade2 >> Grade3 >> Grade4 >> Grade5 ; // *** fixed

    Grade3 =

    // add this line to verify that the grades have been read correctly
    // we can remove it later once we know that this part of the code is working
    std::cout << Grade1 << ' ' << Grade2 << ' ' << Grade3 << ' ' << Grade4 << ' ' << Grade5 << ' ' << '\n' ;
}

main.cpp:16:12: error: assigning to 'int' from incompatible type 'basic_ostream<char, std::__1::char_traits<char> >'
    Grade3 =
           ^

http://coliru.stacked-crooked.com/a/5b8eb257c1e22abf

Look at line 16, column 12, fix the error, repeat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

int main()
{
    // Step 1: Declarations ( Grades, Average)
    int Grade1;
    int Grade2;
    int Grade3;
    int Grade4;
    int Grade5;

    // Step 2 : Request, Input Grades
    std::cout << "Enter five grades with a space in between: " ;
    std::cin >> Grade1 >> Grade2 >> Grade3 >> Grade4 >> Grade5 ; // *** fixed

    // Grade3 = // *** fixed

    // add this line to verify that the grades have been read correctly
    // we can remove it later once we know that this part of the code is working
    std::cout << Grade1 << ' ' << Grade2 << ' ' << Grade3 << ' ' << Grade4 << ' ' << Grade5 << ' ' << '\n' ;
}


Forward to step 3 : Calculate Average
...
...
...
And so on till step 5 is completed and we get something like:
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
 #include <iostream>

int main()
{
    // Step 1: Declarations ( Grades, Average)
    int Grade1;
    int Grade2;
    int Grade3;
    int Grade4;
    int Grade5;

    // Step 2 : Request, Input Grades
    std::cout << "Enter five grades with a space in between: " ;
    std::cin >>  Grade1 >>  Grade2 >>  Grade3 >>  Grade4 >>  Grade5 ;

    // step 3 : Calculate Average
    const double Average = ( Grade1 + Grade2 + Grade3 + Grade4 + Grade5 ) / 5.0 ; // 5.0 to avoid integer division

    // Step 4 : Assign Letter grades by assigning parameters using if else statements.
    // Letters will be assigned accordingly to average calculated
    char letter_grade = 'F' ;
    if( Average >= 90 ) letter_grade = 'A' ;
    else if( Average >= 80 ) letter_grade = 'B' ;
    else if( Average >= 70 ) letter_grade = 'C' ;
    else if( Average >= 60 ) letter_grade = 'D' ;
    // else letter_grade = 'F' ;

    // Step 5 : print out the average and grade
    std::cout << "average: " << Average << "  grade: " << letter_grade << '\n' ;
}
Topic archived. No new replies allowed.