# Thread: Who can spot what I did wrong?

1. ## Who can spot what I did wrong?

Write a function qualityPoints that inputs a student's average and returns 4 if a student's average is 90-100, 3 if the average is 80-89, 2 if the average is 70-79, 1 if the average is 60-69, and 0 if the average is lower than 60.

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

int qualityPoints(int a, int b, int c, int d, int f);
int main() {

int x;
int q;
int a;
int b;
int c;
int d;
int f;

scanf("%d", &x);

q = qualityPoints(a, b, c, d, f);

printf("Student's average is between %d", q );

return 0;

}

int qualityPoints(int a,int b, int c, int d, int f) {

for(a = 100; a >= 90; a--){
if(a >= 90)
return 4;
}
for(b = 89; b >= 80; b--){
if(b >= 80)
return 3;
}
for(c = 79; c >= 70; c--){
if(c >= 70)
return 2;
}
for(d = 69; d >= 60; d--){
if(d >= 60)
return 1;
}
for(f = 59; f >= 0; f--){
if(f < 60)
return 0;
}
}```
What do I have wrong?

2. remove all loops

and write code like

Code:
```if (cond1)
return 4;
else if(cond2)
return 3;
else if(cond3)
return 2;
else if (cond4)
return 1;
else
return 0;```

3. I did it but i have 1 error. It says that I missing a semi-colon before return 0 which makes no sense but when i put it in in changes to two different errors.

4. Originally Posted by jturner38
I did it but i have 1 error. It says that I missing a semi-colon before return 0 which makes no sense but when i put it in in changes to two different errors.

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

int qualityPoints(int a, int b, int c, int d, int f);
int main() {

int x;
int q;
int a;
int b;
int c;
int d;
int f;

scanf("%d", &x);

q = qualityPoints(a, b, c, d, f);

printf("Student's average is between %d", q );

return 0;

}

int qualityPoints(int a,int b, int c, int d, int f) {

if(a >= 90)
return 4;
else if(b >= 80)
return 3;
else if(c >= 70)
return 2;
else if(d >= 60)
return 1;
else(f < 60)
return 0;

}```

6. Code:
`else(f < 60)`
You don't need the (f < 60) part, just the else.

7. Now it says f is not being initialized when I debug it!

8. Originally Posted by jturner38
Now it says f is not being initialized when I debug it!
Look at your code. You are using the variable 'f' without ever assigning a value to it.

9. Originally Posted by bithub
Look at your code. You are using the variable 'f' without ever assigning a value to it.
Well, the entire code doesn't make any sense to me anyway. Why do we need these variables in the first place? Just check if the score is in some range and return some value...

10. Well how do u do a range problem? Unless I go back to my originall part where I had for statements. Did u see what I had before? Ok im getting confused by everybody's input. In order to check a value to see if its in a certain range you have to do what?

11. replace a, b, c, d, & f with x

Code:
```.
.
.
q = qualityPoints(x);
.
.
.
int qualityPoints(int x)
{
if(x >= 90)
return 4;
else if(x >= 80)
return 3;
.
.
.
}```

12. Oh duh! I gotcha. I had thought that originally but i dont y i changed it to multiple variables!

Code:
```#include "stdio.h"
int qualityPoints(int);
int main() {

int x = 0,q = 0;

scanf("%d", &x);

q = qualityPoints(x);

printf("Student's average is between %d", q );

return 0;

}

int qualityPoints(int x) {

int i;
for(i = 100; i >= 90; i--){
if(x >= 90)
return 4;
}
for(i = 89; i >= 80; i--){
if(x >= 80)
return 3;
}
for(i = 79; i >= 70; i--){
if(x >= 70)
return 2;
}
for(i = 69; i >= 60; i--){
if(x >= 60)
return 1;
}
for(i = 59; i>= 0; i--){
if(x < 60)
return 0;
}
}```

14. Originally Posted by shwetha_siddu