Thread: Level 3, homework help!

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    24

    Level 3, homework help!

    Code:
    int k, m;
    double n, a_n, x;
    
    printf("Enter a positive integer m:\n");
    scanf("%d", &m);
    printf("Enter a double -1<x<=1:\n");
    scanf("%d", &x);
    
    for(k=1; k<m+1; k++)
    {
    a_n = x;
    printf("%2d         %8.5f\n", k, a_n);
    }
    }
    I'm just doing something simple right now, scanning. My problem is, instead of the "x" I had made the program scan, I keep getting 0.

    Code:
     1          0.00000
     2          0.00000
     3          0.00000
     4          0.00000
     5          0.00000
    Any help?

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Code:
    scanf("%d", &x);
    ->
    Code:
    scanf("%lf", &x);
    %d is for ints, %lf is for doubles.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Diablo's random level generation
    By glo in forum Game Programming
    Replies: 7
    Last Post: 07-19-2008, 03:04 AM
  2. Listing binary tree numbers by level
    By Nazgulled in forum C Programming
    Replies: 5
    Last Post: 06-16-2008, 10:36 AM
  3. Level Editor
    By jdinger in forum Game Programming
    Replies: 14
    Last Post: 04-03-2003, 06:46 PM
  4. level up 6 times with 40 EXP!?!?!?!
    By Blizzarddog in forum Game Programming
    Replies: 15
    Last Post: 03-05-2003, 12:56 PM
  5. Homework
    By kermi3 in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2001, 03:16 PM