# Calculating A Desired Grade Using C

• 01-19-2013
M_A_T_T
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() {     char grade[5];     float minimumavg[5];     float currentavg[5];     float finaltest[5];     float newgrade [5];     printf("Enter desired grade: \n");     scanf(" %c", grade);     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) {     double grade_calc;     grade_calc = %f * x + (1 - %f) * %f , &finaltest, &finaltest, &currentavg;     return (grade_calc); }```
• 01-19-2013
AndiPersti
Code:

```char grade[5]; float minimumavg[5]; float currentavg[5]; float finaltest[5]; float newgrade [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
• 01-20-2013
M_A_T_T
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() {     char grade;     float minimumavg;     float currentavg;     float finaltest;     float newgrade;     printf("Enter desired grade: \n");     scanf("% c", grade);     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) {     double grade_calc;     grade_calc = finaltest * x + (1 - finaltest) * currentavg;     return (grade_calc); } I got an output of this when I entered "B": Enter desired grade: 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?
• 01-20-2013
std10093
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 *'```
• 01-20-2013
yahzee
You need address operator when scanning char:

Code:

```printf("Enter desired grade: \n");     scanf("%c", &grade);```
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);`

• 01-20-2013
M_A_T_T
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) {     double newgrade;     newgrade = finaltest * x + (1 - finaltest) * currentavg;     return (newgrade);```
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?
• 01-20-2013
stahta01
Quote:

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.