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