Thread: what is my mistake

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    11

    what is my mistake

    Code:
    #include <cs50.h>
    #include <stdio.h>
    
    int
    main(void)
    {
        int days = 0;
        do {
            // user is promted to enter number of days in his month
            printf("Enter number of days in the month: ");
            days = GetInt();
            // program shows number of days entered
            printf("You entered %d days.\n" , days);
            // repeat if input is not 28, 29, 30 or 31
        ) while (31 < days < 28);
    }
    compiler is gcc on fedora and I get this error when compiling

    make: warning: Clock skew detected. Your build may be incomplete.

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    I've had this warning before, and AFAIK, it makes no difference in the final program.

    Also, your program is incorrect:
    - main should return a number (usually 0) at the end
    - you're using ")" instead of "}" on line 15

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Check again line #15, is your condition written correctly?

    EDIT: If not sure, revise C's operators and their uses
    Devoted my life to programming...

  4. #4
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    Your system clock might be skewed. I always recommend installing the ntp package to keep your system clock synchronized to time servers.

    Also the test in the while loop doesn't do what you expect.

  5. #5
    Registered User
    Join Date
    Jul 2012
    Posts
    51
    'make' works by mod times of files. man make.

    The make program uses the makefile data base and the last-modification times of the files to decide which of the files need to be updated.
    Check your system and file times using 'date' and 'ls -la $filename'. If your $filename mod time is off but system time is OK, 'touch $filename'. Also, you can compile with 'gcc -Wall $filename' and the warning should disappear?

    christop suggestion of ntp is a good idea.
    Last edited by fnprintf; 08-14-2012 at 07:57 PM. Reason: typo

  6. #6
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Code:
    while(31 < days < 28);
    Shouldn't this be

    Code:
    while(31 < days && days < 28);

  7. #7
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    404
    Quote Originally Posted by Click_here View Post
    Shouldn't this be

    Code:
    while(31 < days && days < 28);
    So, execute the loop forever?

    I kid, I kid. OP needs to change the comparison operators around.

  8. #8
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by Click_here View Post
    Code:
    while(31 < days < 28);
    Shouldn't this be

    Code:
    while(31 < days && days < 28);
    Nope. That will never be true. Actually, it should be:
    Code:
    while (days > 31 || days < 28);
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  9. #9
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Nope. That will never be true. Actually, it should be:...
    OP has wrong logic in there and written incorrectly. Your way is right.

    31 < days < 28 would make more sense being
    NOT(31 >= days >= 28) -> "Loop when it is not in this domain"

    = !((31>=days) && (days >= 28))
    = ! (31>=days) || !(days >= 28)

    = (31<days) || (days < 28)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. mistake of using awk
    By lehe in forum Linux Programming
    Replies: 6
    Last Post: 04-02-2009, 04:41 PM
  2. What is my mistake ?
    By Freelander1983 in forum C++ Programming
    Replies: 10
    Last Post: 12-11-2007, 09:31 AM