Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C
#include<stdio.h>
main()
{
    printf("enter your marks \n");
	int m=0;
	scanf("%s",&m);
	if (m>90)
	{  
	   printf("congratulations you got GRADE A");	  
	}	
	else	
	{
		if(m>80)
		 {
		  printf("you got B GRADE");	    
		 } 	
		else if(m>75)
		{
			printf("YOU got C grade");
		}	
	    else if(m>70)
	    {
	    	printf("you got D grade");
		}	
		else
		{
			printf("you got E grade");
		}				
	}
}


What I have tried:

I am very new to this coding work and thus am facing issues with this code.
Posted
Updated 21-Jan-22 4:46am
v3

There is not even the attempt of 'looping' in your code.
A simple loop I can imagine:
C
#include<stdio.h>
int main()
{
  char c;
  do
  {
    printf("enter your marks \n");
    int m=0;
    if (  scanf("%d",&m) == 1)
    {
      if (m>90)
      {
        printf("congratulations you got GRADE A");
      }
      else if (m>80)
      {
        printf("you got B GRADE");
      }
      else if (m>75)
      {
        printf("YOU got C grade");
      }
      else if (m>70)
      {
        printf("you got D grade");
      }
      else
      {
        printf("you got E grade");
      }
      printf("\n");
    }
    printf("do you wish to continue?\n");
    scanf(" %c", &c);
  } while (c == 'y');

  return 0;
}
 
Share this answer
 
Comments
Anushka Sharma 2022 21-Jan-22 8:47am    
isn't there any other way to do it without using do-while statement
jeron1 21-Jan-22 10:21am    
You can write the code to use any of the looping constructs, a do-while seems appropriate in this case. Do you have something against a do-while?
CPallini 21-Jan-22 10:49am    
Yes: the C programming language provides (at least ) two other loop constructs, as you may easily find in the many, many, many tutorials freely available on the web,
Anushka Sharma 2022 22-Jan-22 3:52am    
thanks
First you need to add %d% in scanf to get numbers and second add printf("Enter Your Marks:") inside do-while loop to prompt marks for second time and third add || operator because user can enter 'Y' or 'y' for new marks.

#include<stdio.h>
main()
{
    char option;
	int m=0;
	do
	{
	    printf("Enter Your Marks: ");
	    scanf("%d",&m);
	    if (m>90)
    	{  
    	   printf("Congratulations you got GRADE A");	  
    	}	
    	else	
    	{
    		 if(m>80)
    		 {
    		    printf("You got B GRADE");	    
    		 } 	
    		 else if(m>75)
    		 {
    			printf("You got C grade");
    		 }	
    	     else if(m>70)
    	     {
    	    	printf("You got D grade");
    		 }	
    		 else
    		 {
    			printf("You got E grade");
    		 }				
    	}
        
    	printf("\nDo You Want to Continue? (Y/y): ");
        scanf(" %c", &option);
  } while (option == 'Y' || option == 'y');
	
	
	
}
 
Share this answer
 
You should improve your knowledge about loops with visiting some Learn C tutorial to better understand what a loop in C mean. Most obvious are for loops when you can count up or down, or while loops, when you have some controlling condition in your code. See the tutorial for details.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900