/ This program calculates student exam average.
#include <iostream>
#include <string>
usingnamespace std;
void getExamInfo(string, int &);
bool avgCompare(int, int &);
int main()
{
string prompt = "Enter student's exam grade ";
string studName;
int studScore, studAvg, Exam1, Exam2, Exam3, CalAvg;
char grade;
// Get students first name.
cout << "Enter student's name. ";
cin >> studName;
getExamInfo(prompt, Exam1);
getExamInfo(prompt, Exam2);
getExamInfo(prompt, Exam3);
// Original project 1.1 code
// Get exam 1 score.
//cout << "grade from exam 1 = ";
//cin >> Exam1;
// Get exam 2 score.
//cout << "grade from exam 2 = ";
//cin >> Exam2;
// Get exam 3 score.
//cout << "grade from exam 3 = ";
//cin >> Exam3;
// Calculate exam total.
studScore = Exam1 + Exam2 + Exam3;
// Calculate exam total.
studAvg = studScore/3;
// End of Project 1
// Beginning of Project 1.2
// if else condition
// statement to display grade letter.
if (studAvg >= 90)
grade = 'A';
elseif (studAvg >= 80)
grade = 'B';
elseif (studAvg >= 70)
grade = 'C';
elseif (studAvg >= 60)
grade = 'D';
else
grade = 'F';
// Display the average.
cout << "average is "
<< studAvg
<< " "
<<grade;
// Verify grade
cout << "Enter students' calculated average ";
cin >> CalAvg;
// Stop program
system ("pause");
return 0;
}
void getExamInfo(string msg, int &exam)
{
cout << msg;
cin >> exam;
}
bool avgCompare(int studAvg, int &CalAvg)
{
return 0;
}
this is my code so far what i want to do is add in a bool that will look at the calculated value of the studAvg and then allow me to enter in a value to compare it to and then say true or false to the enter value being the same as the calculated value. I have my prototype, but i dont have a call or a function for the prototype. I need help with them i am lost and dont know where to start and I and watching videos and referencing several different books but everybody codes differently and it is becoming overwhelming to find simple reference code that i can look at and say "ok i see i need to try step 1...2...3"
// This program calculates student exam average.
#include <iostream>
#include <string>
usingnamespace std;
void getExamInfo(string, int &);
bool avgCompare(int, int &);
int main()
{
string prompt = "Enter student's exam grade ";
string studName;
int studScore, studAvg, Exam1, Exam2, Exam3, CalAvg;
char grade;
// Get students first name.
cout << "Enter student's name. ";
cin >> studName;
getExamInfo(prompt, Exam1);
getExamInfo(prompt, Exam2);
getExamInfo(prompt, Exam3);
// Original project 1.1 code
// Get exam 1 score.
//cout << "grade from exam 1 = ";
//cin >> Exam1;
// Get exam 2 score.
//cout << "grade from exam 2 = ";
//cin >> Exam2;
// Get exam 3 score.
//cout << "grade from exam 3 = ";
//cin >> Exam3;
// Calculate exam total.
studScore = Exam1 + Exam2 + Exam3;
// Calculate exam total.
studAvg = studScore/3;
// End of Project 1
// Beginning of Project 1.2
// if else condition
// statement to display grade letter.
if (studAvg >= 90)
grade = 'A';
elseif (studAvg >= 80)
grade = 'B';
elseif (studAvg >= 70)
grade = 'C';
elseif (studAvg >= 60)
grade = 'D';
else
grade = 'F';
// Display the average.
cout << "average is "
<< studAvg
<< " "
<<grade <<endl;
// Verify grade
cout << "Enter students' calculated average ";
cin >> CalAvg;
if (CalAvg==studAvg)
{
cout << "Average is Correct.";
}
elseif (CalAvg!=studAvg)
{
cout << "Houston we have a problem!";
}
// Stop program
system ("pause");
return 0;
}
void getExamInfo(string msg, int &exam)
{
cout << msg;
cin >> exam;
}
bool avgCompare(int studAvg, int &CalAvg)
{
return 0;
}
So what i am wanting to do is to create a bool function call avgCompare that will take the place of this portion of code that i just created.
1 2 3 4 5 6 7 8 9 10 11
// Verify grade
cout << "Enter students' calculated average ";
cin >> CalAvg;
if (CalAvg==studAvg)
{
cout << "Average is Correct.";
}
elseif (CalAvg!=studAvg)
{
cout << "Houston we have a problem!";
}
I am starting to understand why you would want to use functions because code can get way out of control and it is much easier to break any code longer than 6 lines into functions. But that dont mean i know how to write them! LOL!!