Like Tree1Likes
  • 1 Post By Salem

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

This is a discussion on problem: WHEN TYPED IN DEV C++,it doesn't run properly(doesn't ask to input marks.) within the C Programming forums, part of the General Programming Boards category; 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); ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,555
    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.
    King Mir likes this.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-07-2010, 05: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, 07:48 PM
  3. Loop doesn't seem to function properly
    By TeQno in forum C++ Programming
    Replies: 1
    Last Post: 01-31-2005, 04:25 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21