Thread: problem: WHEN TYPED IN DEV C++,it doesn't run properly(doesn't ask to input marks.)

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    1

    problem: WHEN TYPED IN DEV C++,it doesn't run properly(doesn't ask to input marks.)

    Code:
     #include<stdio.h>
    #include<conio.h>
    void main()
    {
         int roll,fm,sm,tm,total;
         float avg;
         printf("Enter the the roll number\n");
         scanf("%d\n",&roll);
         printf("Enter the first_marks");
         scanf("%d\n",&fm);
         printf("Enter the second_marks");
         scanf("%d\n",&sm);
         printf("Enter the third_marks");
         scanf("%d\n",&tm);
         total=fm+sm+tm;
         avg=total/3;
         printf("REPORT CARD\n");
         printf("The marks of three subjects are %d %d %d\n",fm,sm,tm);
         printf("The total marks are %d\n",total);
         printf("The average is %f ",avg);
         getch();
         }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Remove the \n from your scanf calls.

    \n in scanf doesn't mean skip exactly one \n
    It means ANY sequence of \n, space, tab.

    So in order to make it terminate, you would have to type in at least 1 character which isn't white space, after pressing return for the last field.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-07-2010, 06:53 AM
  2. don't understand why this code doesn't work properly
    By artistunknown in forum C Programming
    Replies: 10
    Last Post: 01-23-2010, 08:48 PM
  3. Loop doesn't seem to function properly
    By TeQno in forum C++ Programming
    Replies: 1
    Last Post: 01-31-2005, 05:25 PM