# Thread: how can i write it shorter?

1. ## how can i write it shorter?

so i'm beginner and i think this is weird(in if and do function) have another easy way?
Code:
```#include"stdio.h"
int main(){
int a,b,c,sum=0;

do{    printf("put  A : ");
scanf("%d",&a);
}
while(a>30);

do{    printf("put  B : ");
scanf("%d",&b);
}
while(b>30);

do{    printf("put  C : ");
scanf("%d",&c);
}
while(c>40);

sum=a+b+c;
//printf("sum = %d",sum);

if(sum>=80){ printf("A");}
if(sum>=75&&sum<=79){ printf("B+");}
if(sum>=70&&sum<=74){ printf("B");}
if(sum>=65&&sum<=69){ printf("C+");}
if(sum>=60&&sum<=64){ printf("C");}
if(sum>=55&&sum<=59){ printf("D+");}
if(sum>=50&&sum<=54){ printf("D");}
if(sum<50){ printf("F");}
}```

2. You can simplify your conditions: since you already check for 80+ for A, you only need to check for 75+ for B+. You dont need to check for <= 79 because if the number was > 79, it would have been under the A+ condition.

This also means that you can create two arrays: an array of ints containing the lower bounds of the grades, and another corresponding array of strings containing the letter grades. You could then loop over the array of ints and check.

3. Some food for thought: You may want to consider a look up table

If you had an array of strings with 20 elements, you could do something like this...
Code:
`result=lookupArray[total/5];`