Thread: Very easy code I know...

  1. #1
    Registered User
    Join Date
    Jan 2011

    Very easy code I know...

    it is giving me problems though, I am a beginner and cannot find the reason for this code to not work properly, it compiles but the output it gives is way off

    //convereting hours to seconds
    #include <stdio.h>
    //define constants
    #define SECONDS_IN_HOUR 3600
    int main () {
        //introduce variables
        float hours_waited, seconds_waited;
        //get user input
        printf("How many hours were you waiting?\n");
        scanf("%.2f", &hours_waited);
        seconds_waited = hours_waited*SECONDS_IN_HOUR;
        printf("You waited for %.2f seconds!!\n", seconds_waited);
        return 0;

  2. #2
    Join Date
    Dec 2007
    scanf("%.2f", &hours_waited);
    You can't use .2 in there. Just use %f.

    If you compile your code with warnings turned up, you would find these sorts of problems:

    ucf.c:15: warning: unknown conversion type character ‘.’ in format
    ucf.c:15: warning: too many arguments for format

  3. #3
    Registered User
    Join Date
    Jan 2011
    Ah thank you, I am using Dev C++ how do I turn my warnings up?

  4. #4
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Cambridge, UK
    Quote Originally Posted by UCFuser View Post
    Ah thank you, I am using Dev C++ how do I turn my warnings up?
    Thought by default wanring was turned on Dev-C++. Anyway this the way you do it, to override the compiler setting on the GUI.

    Tools -> Compiler Options

    In the Add the following commands when calling compiler test box type
    -W -Wall

    To turn on the warning.

    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory Leak in AppWizard-Generated Code
    By jrohde in forum Windows Programming
    Replies: 4
    Last Post: 05-19-2010, 04:24 PM
  2. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM