I am working on displaying student name, test score, average marks and grade as an output.
This is what I have been working on, but still I couldn't manage to display the output.. The input must be get from the user and, which is the student name and the test score.

#include <conio>
#include <iostream>

void calculateAverage(int&);         
char calculateGrade(int&, char&);

void main()
{
   int avg, avrge;
   char gd;
   string stdntName;

   cout <<"Enter the student name: "<<endl;
   cin >> stdntName;
   cout << "\nStudent name is: " << stdntName<<endl;
  calculateAverage(avg);
  cout << "The average marks are :/n " << avg <<endl;
  calculateGrade(avrge,gd);
  cout <<"Grade is : "<< gd<<endl;
}

void calculateAverage(int& average)
{
    int sum=0,score;
   cout<< "Enter all of the test score: " << endl;
    for (int i = 0; i <5; i++)
   cin >> score;
   cout << score;
   sum = sum + score;
   average = sum/5;

}

char calculateGrade(int& avrg, char& grade)

{

   if (avrg >=90 && avrg <=100)
    grade = 'A';
   else
    if (avrg >=80 && avrg <= 89)
        grade = 'B';
        else
            if (avrg >= 70 && avrg <= 79)
            grade = 'C';
           else
            if (avrg >= 60 && avrg <= 69)
                grade = 'D';
            else
                if (avrg >= 59)
                grade = 'F';                        //determine grade

    return grade;
}

I know there's something wrong with this coding, because I didn't manage to produce the output, eventhough, there's no error while compiling. Do help me please. Need to submit it by tomorrow. thanks

Recommended Answers

All 9 Replies

Try adding
system("pause");
to the end after you print out the grade.

My guess is that it's working properly, but it runs and prints out all the information then closes not giving you a chance to look at the output. That line basically tells the command line to stay open until the user presses another key.

this error occured while compiling:
Call to undefined function 'system'


and also, it doesn't output the right answer...

@sparksterz : No you should not use system("pause") to view the output.It has been discussed here a lot number of times. You can use cin.get() instead and it too will work in the same way.

@yuha : Not one there are several things wrong with this code.

1) Usage of <conio> which is already extinct.
2) Usage of std::cout std::string etc is required, or atleast usage of standard namespace as

#include<iostream>
using namespace std;
// Code continues...

is required.
3)Using int main and return 0 at the end instead of the void main().
4)Your calculateAverage function is flawed it doesnt calculate the average at all.

void calculateAverage(int& average)
{
int sum=0,score;
cout<< "Enter all of the test score: " << endl;
for (int i = 0; i <5; i++)
cin >> score;
cout << score;
sum = sum + score;
average = sum/5;
}

the above two statements are not included in the for loop at all and so you'll never get the average.It should be

void calculateAverage(int& average)
{
int sum=0,score;
cout<< "Enter all of the test score: " << endl;
for (int i = 0; i <5; i++)
{
cin >> score;
cout << score;
sum = sum + score;
}
average = sum/5;
}

5)Your grade function needs a lot of restructuring so that it outputs the right grade.

up by below your includes you probably also want to add
using namespace std;
cout, cin, and system are all part of this namespace, it should be able to find it then.

I guess you could use cin.get();, but if you were going to exit the program after doing this anyways what's so wrong with using system("pause");?

i still couldn't read the output...plus, can you explain more on how to altered my calculateGrade function...

You don't need to use the reference variables at all as char calculateGrade(int& avrg, char& grade) This is enough :

char calculateGrade(int avrg)
{
char grade;
//After this same function definition as you have done no changes...
}

And now comes the change part...With the above code you cannot use

calculateGrade(avrge,gd);
cout <<"Grade is : "<< gd<<endl;

To output your grade...
Firstly the function call would be calculateGrade(averge) This function returns a character which is your grade.

Here I leave you on your own, Try to find out where and how to modify in your main function to achieve your objective.

okay...thanks for your help... n_n

okay...thanks for your help... n_n

Ya once you feel your objective is served then close the thread, so that others can concentrate on other threads.
Read the forum rules on using the code tags.And you can also vote posts and persons positively and negatively all this is mentioned in the forum.Go through it and ya Welcome to DANIWEB !

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.