Home > OS >  I wrote a code in C language to print passed/not passed on basis of his marks. No matter, what I inp
I wrote a code in C language to print passed/not passed on basis of his marks. No matter, what I inp

Time:09-19

# include<stdio.h>

int main() {
    
    int marks;
    printf("enter marks: ");
    scanf("enter marks: %d ", &marks);

    if(marks > 30)
    {
        printf("passed");

    }

    else
    {
        printf("not");
    }
    
    return 0;

}

The criteria that I put doesn't help in the output, even if enter marks as 14, then too it displays passed. I am a beginner, so please help.

CodePudding user response:

printf("enter marks: ");
scanf("enter marks: %d ", &marks);

Is not correct.

You do not put a "prompt" in scanf. Only the value you want to read.

It should be:

scanf("%d", &marks);  // Prompt was already done with printf on prior line

CodePudding user response:

#include <stdio.h>
#include <conio.h>

int main() {
    
    int marks;
    printf("enter marks:");
    scanf("%d",&marks);

    if(marks > 30)
    {
        printf("passed");

    }

    else
    {
        printf("not");
    }
    
    return 0;

}

its working fine

  •  Tags:  
  • c
  • Related