1. ## Calculating A Desired Grade Using C

Hello,

I am trying to create a program using C where the user enters a desired grade (A, B, C) , along with the minimum average needed for that grade (90%, 80%, 70%), their current average, and how much the final counts as a percentage of the course grade (25%).

The program should output:

You need a score of ... on the final to get a ...

Currently, I am getting a error that says "expected expression before '%' token on the line where it says grade_calc =

This is what I have so far and my new function is giving me a headache with new debugging problems. If someone could help me fix my current problem and give me a nudge in the right direction as to what to do I would greatly appreciate it.

insert
Code:
```#include <stdio.h>

int
main()
{

float minimumavg[5];
float currentavg[5];
float finaltest[5];

printf("Enter minimum average required: \n");
scanf("%f", &minimumavg);

printf("Enter current average in course: \n");
scanf("%f", &currentavg);

printf("Enter how much the final accounts for as a percentage: \n");
scanf("%f", &finaltest);

printf("You need a score of %f on the final to get a % c" , &newgrade, &grade);

double
grading(double x, float currentavg, float finaltest)
{

grade_calc = %f * x + (1 - %f) * %f , &finaltest, &finaltest, &currentavg;

}```

2. Code:
```char grade[5];
float minimumavg[5];
float currentavg[5];
float finaltest[5];
Why do you use arrays?

Code:
`printf("You need a score of %f on the final to get a % c" , &newgrade, &grade);`
There shouldn't be a space between "%" and "c".

Code:
`grade_calc = %f * x + (1 - %f) * %f , &finaltest, &finaltest, &currentavg;`
That's just wrong. You don't need format specifiers if you want to use variables in expressions. Just write it like:
Code:
`grade_calc = finaltest * x + (1 - finaltest) * currentavg;`
You are also missing the return statement and the closing } in main().

Bye, Andreas

3. Thank you Andreas. I thought the square brackets represented the length of the input, not arrays. I am just learning this for the first time and I greatly appreciate the help. After I did your suggestions, and changed the code to this:

Code:
```#include <stdio.h>

int
main()
{

float minimumavg;
float currentavg;
float finaltest;

printf("Enter minimum average required: \n");
scanf("%f", &minimumavg);

printf("Enter current average in course: \n");
scanf("%f", &currentavg);

printf("Enter how much the final accounts for as a percentage: \n");
scanf("%f", &finaltest);

printf("You need a score of %f on the final to get a % c" , &newgrade, &grade);

return(0);
}

double
grading(double x, float currentavg, float finaltest)
{

grade_calc = finaltest * x + (1 - finaltest) * currentavg;

}

I got an output of this when I entered "B":

B
Enter minimum average required:
Enter current average in course:
Enter how much the final accounts for as a percentage:
You need a score of 0.000000 on the final to get a b```
It successfully runs now, its just not asking for the inputs after I enter in the grade. How can I get it to ask the minimum average, current average, without skipping it?

4. The warnings hold the answer

Code:
```linux05:/home/users/std10093>gcc -Wall px.c -o px
px.c: In function 'main':
px.c:13: warning: format '%c' expects type 'char *', but argument 2 has type 'int'
px.c:26: warning: format '%f' expects type 'double', but argument 2 has type 'float *'
px.c:26: warning: ' ' flag used with '%c' printf format
px.c:26: warning: format '% c' expects type 'int', but argument 3 has type 'char *'```

5. You need address operator when scanning char:

Code:
```printf("Enter desired grade: \n");
You are using address operator while printing variables, it will just print their memory addres not their value, try this:

Code:
`printf("You need a score of %f on the final to get a %c" , newgrade, grade);`

6. Thank you so much for all the help. I have made the correct changes with the address operators, but the last thing that is confusing me is the function that I have preforming the calculations. It is outside the main function, and I want it to compute the value needed and send it back to the main function.

I have tried debugging it and I still cannot get the other function to work. This is what I have for my other function besides main called grading:

Code:
```double
grading(double x, float currentavg, float finaltest)
{

newgrade = finaltest * x + (1 - finaltest) * currentavg;

And this is the last line in the function main where it should take the value it gets from the other function and feed it in here:

Code:
`printf("You need a score of %f on the final to get a %c" , newgrade, grade);`
I am getting an output of 0.0000000 needed to get a B. Why isn't my other function working?

7. Originally Posted by M_A_T_T
Why isn't my other function working?
Which line of code is calling the function?
Is it storing the result of calling the function?

Edit: FAQ that might help: Functions in C - Cprogramming.com

Tim S.