Thread: Whats wrong with this?

  1. #1
    Registered User
    Join Date
    May 2004

    Whats wrong with this?

    im writing this stupid program but somthing is wrong and i cant find what it is,no matter which ten numbers i input the output is always 0,can any body tell me why and how to fix it,thanks

    #include <stdio.h>

    float v[10];
    int i,imin,imax;
    for (i=0;i<=9;i++) scanf("%f",&v[i]);
    for (i=0;i<=9;i++)
    if (v[i]<v[imin]) imin=i;
    printf ("\n%d\n",v[imin]);

  2. #2
    Registered User
    Join Date
    Apr 2002
    You use the %d specifier when you call printf instead of %f.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    maybe because:
    float v[10];
    /* ... */
    printf ("\n%d\n",v[imin]);
    Also use code tags and main returns an int

  4. #4
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    Also, it's usually a safe thing but you can't always depend on your compiler to initialize a varaible to 0. It doesnt look like a problem here but is something good to know.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM