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;
inputNumbers(number1,number2,number3);
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:";
cin>>number1;
//prompt for number 2
cout<<"Enter second grade:";
cin>>number2;
//prompt for number 3
cout<<"Enter third grade:";
cin>>number3;
}//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:";
}
}

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

how can i call the function assign grade?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.