Trying to write some code that will average my grade (No real use just for practice)

Gotta start off by saying that im pretty much brand new to code, and the code i used for this program is C not C++...

Basically im im trying to write a simple code just for the fun of it that will let me average the grades in 4 of my classes. (Has no real legitimate use, i just want to practice a little like i said). But there seems to be a problem.

You see, I wanted it set up so that biased on what grade you get, it will output a different message. For instance, below a 65 will say "Uh-oh! Your failing with a <GPA here> GPA!". Now the first problem i came into was just my lack of knowledge... or really lack of ability to ask a question i suppose. I wanted it so it would take into account the entire range of values instead of individual numbers... but i was not too certain on what that is called. But to sum it up, lets say i want anyone who has a gpa of 90 to 100 to get a message saying "great job!" how would i go about doing that without entering every number individual? because to do that with the range from 1 to 64 killed me, and on top of that it didnt even work! Here is the way i thought it was done.

1
2
3
else if(gpa==65 || 66 || 67 || 68 || 69 || 70){
         printf("I'd studdy more! You only have a %d GPA!", gpa);
    }//*Code for 65 to 70 GPA//* 


as you can see that is part of an else if statement i was making... The instructor i was listening too said that "||" ment "or"... But he didnt use them in the way i did i suppose. Hopefully i have explained myself enough, im just going to post the rest of the code in here to see what pointers anyone can give me.

The way in which it dosint work is that no matter what the average is, the message always given is from the 2nd els if statement... no matter what, and i cant figure it out

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include <conio.h>

int main(void)
{
    int science;
    int math;
    int socialstudies;
    int english;
    int total;
    int gpa;
    
    printf("Welcome to the grade averager! Where you can enter your math,\nscience, social studdies, and elgish grades and get the average!\n");

    printf("Pleas enter your science grade here:");
    scanf("%d", &science);
    
    printf("Pleas enter your math grade here:");
    scanf("%d", &math);
    
    printf("Pleas enter your social studies grade here:");
    scanf("%d", &socialstudies);
    
    printf("Pleas enter your english grade here:");
    scanf("%d", &english);
    
    total = ((science + math) + socialstudies) + english;
    
    gpa = total / 4;
    
    if (gpa == 100){
    printf("Nice going! you have a %d!!!", gpa);
    } //*Code for perfect 100% GPA//*
    
    else if(gpa==1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15 || 16 || 17 || 18 || 19 || 20 || 21 || 22 || 23 || 24 || 25 || 26 || 27 || 28 || 29 || 30 || 31 || 32 || 33 || 34 || 35 || 36 || 37 || 38 || 39 || 40 || 41 || 42 || 43 || 44 || 45 || 46 || 47 || 48 || 49 || 50 || 51 || 52 || 53 || 54 || 55 || 56 || 57 || 58 || 59 || 60 || 61 || 62 || 63 || 64){
         printf("Uh-oh! Your failing with a %d GPA!!!", gpa);
    }//*Code for failing GPA (1 to 64)//*
    
    else if(gpa==65 || 66 || 67 || 68 || 69 || 70){
         printf("I'd studdy more! You only have a %d GPA!", gpa);
    }//*Code for 65 to 70 GPA//*
    
    else if(gpa==71 || 72 || 73 || 74 || 75 || 76 || 77 || 78){
         printf("You're passing with a %d GPA!", gpa);
    }//*Code for 71 to 78 GPA//*
    
    else if(gpa==79 || 80 || 81 || 82 || 83 || 84 || 85 || 86 || 87 || 88){
         printf("You're passing with a %d GPA!", gpa);
    }//*Code for 79 to 88 GPA//*
    
    else if(gpa==89 || 90 || 91 || 92 || 93 || 94 || 95 || 96 || 97 || 98){
         printf("Your doing great! you have a %d GPA!", gpa);
    }//*Code for 89 to 98 GPA//*
    
    else if(gpa==99){
         printf("Amazing! %d", gpa);
    }//*For 99 GPA//*
    
    getch();
    }
Last edited on
1
2
3
else if(gpa==65 || 66 || 67 || 68 || 69 || 70){
         printf("I'd studdy more! You only have a %d GPA!", gpa);
    }//*Code for 65 to 70 GPA//*  
would be written:
1
2
3
else if(gpa==65 || gpa==66 || gpa==67 || gpa==68 || gpa==69 || gpa==70){
         printf("I'd studdy more! You only have a %d GPA!", gpa);
    }//*Code for 65 to 70 GPA//*  
or, more succinctly:
1
2
3
else if(gpa > 64 && gpa < 71){
         printf("I'd studdy more! You only have a %d GPA!", gpa);
    }//*Code for 65 to 70 GPA//*  
Thank you very much sir!..

I only started coding about 2 days ago, so thank you for the help. :)
Topic archived. No new replies allowed.