0

I'm trying programming 1st time and not getting the output of this program.Though it looks simple but the code doesn't prints after taking the input like name, roll, marks obtained by student. I have attached the screenshot of compiler. Thank you!

#include<stdio.h>

int main()
{

    int roll,phy,che,ca,total;
    float percentage;
    char name[20];
    
    printf("enter the name of student: ");  //studentname
    scanf("%s",&name);
    printf("enter the roll number: ");      //roll number
    scanf("%d",&roll);
    printf("enter the marks obtained in phy,che,ca: "); //marks obtained/subject
    scanf("%d%d%d ",&phy,&che,&ca);
    
    //doesnt works from here.
    
    total= (phy+che+ca);        //calculating total marks 
    printf("the total marks obtained is %d\n",total); 
    percentage =total/3.0;          //calculating percentage student got.
    printf("the total percentage obtained is %d\n",percentage);
    
    if(percentage>=80)
        printf("first division\n");             //first division
    else if(percentage>=60 && percentage<=80)
        printf("second division\n");            //second division
    else if(percentage>=60)
        printf("third divison\n");              //third division
    else if(percentage>=10)
        printf("you failed!\n");                //failed
    else
        printf("invalid input\n");              //invalid input
    
    return 0;
    
}

screenshot of the compiler

Gerhardh
  • 9,405
  • 2
  • 12
  • 34
  • 1
    Welcome to SO. Please do not add pictures of text. Instead just copy&paste the text directly into your question. – Gerhardh May 03 '21 at 07:31
  • 3
    One problem is you're trying to use `%d` format for a `float`. That won't work. – Tom Karzes May 03 '21 at 07:31
  • `name` is already a pointer, no `'&'` before it in `scanf("%s",&name);` You can't use ANY input function correctly unless you ***check the return*** to validate whether the input succeeded or failed. Unless you provide a *width-modifier* in your `"%s"` conversion, it is no safer than using `gets()`. See [Why gets() is so dangerous it should never be used!](https://stackoverflow.com/q/1694036/3422102) – David C. Rankin May 03 '21 at 07:32
  • 1
    Hey, welcome to SO. Please [read guidelines](https://stackoverflow.com/help/how-to-ask) on asking questions. The [scanf](https://www.mankier.com/3/scanf) function could get handful, so I strongly recommend reading the linked manual page first. If you are trying this on non-standard compilers like TurboC or older Microsoft Visual C++, please read their documentation thoroughly. And when you find it difficult, please ask a clear and specific question here. Thanks. – Unmanned Player May 03 '21 at 07:55

1 Answers1

1
scanf("%d%d%d ",&phy,&che,&ca);

There is an extra blank character in format. So you should input a more character after you input 3 integers.

And you shouldn't use %d to print a float type variable, you should use %f.

guapi
  • 123
  • 6