ok I did some work to clarify what i what to do a little better.
Code:
// This program calculates student exam average.
#include <iostream>
#include <string>
using namespace 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';
else if (studAvg >= 80)
grade = 'B';
else if (studAvg >= 70)
grade = 'C';
else if (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." <<endl;
}
else if (CalAvg!=studAvg)
{
cout << "Houston we have a problem!" <<endl;
}
// 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.
Code:
// Verify grade
cout << "Enter students' calculated average ";
cin >> CalAvg;
if (CalAvg==studAvg)
{
cout << "Average is Correct." <<endl;
}
else if (CalAvg!=studAvg)
{
cout << "Houston we have a problem!" <<endl;
}
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!!