this program is running, but the problem is., the function that I called didnt give me the accurate answer.. if you looki into my source.. what was the problem?? is the formula?? or the wrong way of calling functon?? or the whole source of my program.?

this program should able to compute the the Grades in averaging., then it will give the Equivalent..

^_^

``````int grade_average(int a,int b,int c)
{

}``````

The above function isn't working correctly. ( grade_average(5,5,5) == 11 in your version)

``````int grade_average(int a,int b,int c)
{
return (a+b+c)/3;
}``````

hmm your function returns and int when it should return a float or double

I reckon final_grade=(a+b+c)/3; should have brackets around a+b+c as well.

shouldn't your scanf("%d",&Gone); have a little ampersand sign as well?

And you need to work on your indentation.

Don't forget this is c++, so I have to ask the question why are you using c functions etc.

Please don't attach or link to code if it can be more easily embedded in your post. A 70 line program is short enough to fit, and it makes helping you easier.

>didnt give me the accurate answer

``final_grade=a+b+c/3;``

You want an average, which means summing all of the items first, then dividing by the number of items. C++'s precedence rules (and C's as well, since this looks like C code) are intuitive in that multiplication and division go before addition and subtraction. You need to surround the addition in parens:

``final_grade=(a+b+c)/3;``

Your code is actually broken, I'm surprised it works at all.

>scanf("%s",&Subname);
Subname is already a pointer, you don't need to use the address-of operator here.

>scanf("%d",Gone);
>scanf("%d",Gtwo);
>scanf("%d",Gthree);
Gone, Gtwo, and Gthree are all integers, you do need to use the address-of operator here because they're not pointers.

``````int grade_equivalent(int grade)
{
float equivalent;
equivalent=1.0;
equivalent=1.25;
equivalent=1.5;
equivalent=1.75;
equivalent=2.0;
equivalent=2.25;
equivalent=2.75;
equivalent=3.0;
equivalent=4.0;
else
equivalent=5.0;

return equivalent;
}``````

Note that without an intervening else if, an if statement is independent of any other if statements. Any of the previous if statements to the last one will essentially have no effect because functionally, your function looks like this:

``````int grade_equivalent(int grade)
{
float equivalent;

equivalent=4.0;
else
equivalent=5.0;

return equivalent;
}``````

In other words, the else only applies to the last if. You can fix that by making an else if chain:

``````int grade_equivalent(int grade)
{
float equivalent;
equivalent=1.0;
equivalent=1.25;
equivalent=1.5;
equivalent=1.75;
equivalent=2.0;
equivalent=2.25;
equivalent=2.75;
equivalent=3.0;