Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how to describe the given grade

+4 votes
asked Sep 8, 2020 by Gowtham .G Gowtham .G (160 points)
#include <stdio.h>
{
int main();

    char [10];
    char grd;
    scanf("%c",&grd);
    switch(grd)
    {
        case 'E':
          printf("Excellent");
          break;
        case 'V':
          printf("Very Good");
          break;
        case 'G':
           printf("Good");
           break;
        case 'A':
           printf("Average");
           break;
        case 'F':
           printf("Fail");
           break;
    }
 return o;
}

2 Answers

0 votes
answered Sep 9, 2020 by LiOS (6,160 points)

I'm not too sure what your question is but there are a few issues in the code.

  • Misplace of { in line 2
  • Incorrect declaration of main statement
  • char[10] - This is incorrect and appears to be not needed. If it is, perhaps char a[10] will suffice.
  • A switch statement should have a "failsafe", by having a default case. This is executed if none of the cases match.
  • return 0 not o

Final Code:

#include <stdio.h>

int main(){
    
    char grd;
    
    printf("Enter grade: ");
    scanf("%c",&grd);
    
    switch(grd){
        case 'E':
          printf("Excellent");
          break;
        case 'V':
          printf("Very Good");
          break;
        case 'G':
           printf("Good");
           break;
        case 'A':
           printf("Average");
           break;
        case 'F':
           printf("Fail");
           break;
        default:
           printf("Grade entered not available");
    }
 return 0;
}

commented Sep 10, 2020 by Peter Minarik (15,580 points)
A small comment here: I usually end the default: case as well with a break.

I do it for symmetry. Also, if someone decides do add a new case after the default (which is not the usual place, but syntactically valid), it would not fall through to the new case if default is selected. Just to be on the safe side. ;)
0 votes
answered Sep 19, 2020 by Jyoti Rajak (140 points)
Mistake { line 2
Mistake Main() {
Return 0 not o

Final code:

#include <stdio.h>

int main();
   {
    char grd;
    scanf("%c",&grd);
    switch(grd)
    {
        case 'E':
          printf("Excellent");
          break;
        case 'V':
          printf("Very Good");
          break;
        case 'G':
           printf("Good");
           break;
        case 'A':
           printf("Average");
           break;
        case 'F':
           printf("Fail");
           break;
          default:
         printf("Grade not available");
    }
 return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...