Code problem

This is a discussion on Code problem within the C Programming forums, part of the General Programming Boards category; Code: /* simply exercise */ #include <stdio.h> /* function main begins program execution */ int main() { int grade /* ...

  1. #1
    Registered User dot_rain's Avatar
    Join Date
    Nov 2003
    Posts
    7

    Red face Code problem

    Code:
    /* simply exercise */
    #include <stdio.h>
    
    /* function main begins program execution */
    int main()
    {
       int grade   /* declare */
       
       printf( "Enter your grade: " );
       scanf( "%d", &grade );
    
       if ( grade >= 90 )
          printf( "A\n" );
       else if ( grade >= 80 )
          printf( "B\n" );
       else if ( grade >= 70 )
          printf( "C\n" );
       else
          printf( "D\n");
    
    return 0;   /* end program successfully */
    
    } /* end function main */
    no matter whatever number I enter , it just show A

    plz let me know what's the problem .
    Thanks

    Edit : prolem solved , thanks
    Last edited by dot_rain; 11-21-2003 at 03:30 PM.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >scanf( "%d", grade );
    Should be
    Code:
    scanf( "%d", &grade );
    scanf requires an address so that it can modify the variable you pass it instead of a copy. And you're missing a semicolon in the declaration:
    Code:
    int grade   /* declare */
    But I assume that was a typo when you posted, otherwise it wouldn't compile.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code problem
    By sybariticak47 in forum C++ Programming
    Replies: 9
    Last Post: 02-28-2006, 10:50 AM
  2. Problem with game code.
    By ajdspud in forum C++ Programming
    Replies: 5
    Last Post: 02-14-2006, 05:39 PM
  3. problem with selection code
    By DavidP in forum Game Programming
    Replies: 1
    Last Post: 06-14-2004, 01:05 PM
  4. Replies: 5
    Last Post: 12-03-2003, 04:47 PM
  5. Help with code for simple Y2K problem
    By Mule in forum C++ Programming
    Replies: 3
    Last Post: 03-05-2003, 11:53 PM

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