this is a progarm i have created to calculate srudent grades given the three grades. the computer then works out te average and assigns a grade depending if average is more than 50. the program stops after giving the average of the three grades and doesnt output whether pass of fail. can someone please help me fix this and let me know what i am doing wrong. thankyou.
coding shown below.

#include <iostream.h>

//function declarations
void inputNumbers(int&,int&,int&);
int calculateAverage(int,int,int);
void displayAverage(int);

void main()
{//start of function main
int number1, number2, number3, average;
average= calculateAverage(number1,number2,number3);
displayAverage (average);
}//end of function main

//definition of function inputNumbers
void inputNumbers(int&number1,int&number2,int&number3)
{//start of function inputNumbers
cout<<"Enter first grade:";
//prompt for number 2
cout<<"Enter second grade:";
//prompt for number 3
cout<<"Enter third grade:";
}//end of function input numbers

//definition of function calculateAverage
int calculateAverage(int number1, int number2, int number3)
{//start of function calculateAverage
int average;
average= number1+number2+number3/3;
return average;
}//end of function calculateAverage

//definition of function displayAverage
void displayAverage(int average)
{//start of function displayAverage
cout<<"The Average of the three grades is "<<average;
}//end of function displayAverage

//assign whether pass or fail

char assignGrade(int average)
if (average > 50) {
cout << "Pass:";
else if(average == average) {
cout << "Pass:";
else {
cout << "Fail:";
cout << "Fail:";

10 Years
Discussion Span
Last Post by Anonymusius
char assignGrade(int average)
     if (average => 50)
         cout << "Pass:";

/*else if(average == average) {
cout << "Pass:";
}*/ //this is like asking wether 1 == 1, this makes no sense and seem to be added later sort off it makes no sense and should be removed (I think)

     else {
         cout << "Fail:";
         cout << "Fail:"; //He fail's twice? Awww

You said that only the outputting of the grade didn't work so I just leave it by this. Code is untested

You should to always indent your code.

And you don't see it because you never call the function assigngrade


assigngrade(average); You should look at the subject of scope again. In function assigngrade you ask for an variable called average, which because of that override's the automatic one.

In the function calculateAverage you asign an new variable average, overriding the automatic one in main. You pass it by returning it, which is not necessary in this case. I should advise you to pass so less variable's as possible since everytime you do that the computer makes an copy of that variable.

But look at the chapter about scope again and you will understand.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.