| | |
student grades program doesnt work how it should
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2006
Posts: 10
Reputation:
Solved Threads: 0
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:";
}
}
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 should to always indent your code.
And you don't see it because you never call the function assigngrade
Last edited by Anonymusius; Oct 25th, 2006 at 10:34 am. Reason: code problem
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.
![]() |
Similar Threads
- Internet explorer pop up blocker doesnt work (Web Browsers)
- python mysql doesnt work?plz help (Python)
- Help with a java program home work assignment (Java)
- Creative webcam doesnt work!!! HELP!!!!! (USB Devices and other Peripherals)
- errors make me close program (C#)
- My phpbb forum doesnt work ? (PHP)
Other Threads in the C++ Forum
- Previous Thread: match_regex iterator syntax
- Next Thread: help please asap!
Views: 1577 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





