I was trying to learn c i wanted to find marks using the code the issue is that it is not giving me the correct output and i wanted it to loop if the marks are less i wawnted to repeat it . This is the code that i wrote
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
void mygrade(int grades)
{
if (grades >= 90)
{
printf("High distinction");
}
else if (grades > 80 < 70)
{
printf("Your Grade is Distinciton");
}
else if (grades > 60 < 70)
{
printf("Credit");
}
else if (grades > 50 < 60)
{
printf("Pass");
}
else if (grades < 50)
{
printf("Fail");
}
else
{
printf("Enter vaild Marks");
}
}
void main()
{
int grades;
printf("Enter your score for this unit\n");
scanf("%d", &grades);
printf("your grade for this unit is: %d ");
}
CodePudding user response:
Your mistake is to use comparisons like "(grades > 80 < 70)", which is not allowed in C . Replace them with the form "((grades > 70) && (grades < 80))"
CodePudding user response:
If you want the program work as you write in the picture, there are three things to do:
- You can just use
if (grades >= 90)
// …
else if (grades >=80)
// …
// and so on
since else if
statement will be trigger only if all cases above it are not true.
You need to call
mygrade()
function in themain()
function so that it will run.If you want to repeat the program if the grades are less than 50, then you can use
do-while
loop.
do
{
//…
}while (grades < 50);