Thread: Do while loop fails when more conditions are added

  1. #1
    Registered User
    Join Date
    Mar 2014
    Posts
    1

    Unhappy Do while loop fails when more conditions are added

    I'm trying to write a piece of code that calculates the difference in days between two manually input dates.

    The part of my code that's causing problems is:

    xxx

    When running the code and prompted to enter the date, if I input for example 31/12/2014, it'll be rejected and send me back to the beginning of the loop. Any date with 31 days involving months 1, 3, 5, 7, 8, 10 or 12 causes this problem. All other valid dates however work perfectly fine (e.g. 30/4/2014).

    Something possibly worth mentioning is that, when I take out all other conditions from the loop, i.e.

    xxx

    it works fine (31/12/2014 is accepted), but of course I need all of the other conditions in there too.

    Any ideas?

    Thanks
    Last edited by UpDownStrange; 03-29-2014 at 01:49 PM.

  2. #2
    Registered User
    Join Date
    Nov 2012
    Posts
    157
    you should know that

    this:
    Code:
    (((mm1 == 1 || 3 || 5 || 7 || 8 || 10 || 12) && dd1 > 31));
    is not the same as this
    Code:
    (((mm1 == 1 || mm1 ==3 || mm1 ==5 || mm1 ==7 || mm1 ==8 || mm1 ==10 || mm1 ==12) && dd1 > 31));
    Also i suggest putting all that into a function, my hatred for complexity in my main grows each passing day

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. While loop with OR conditions, beginner
    By Paulsim in forum C++ Programming
    Replies: 5
    Last Post: 09-11-2012, 06:59 AM
  2. combined conditions in For loop
    By sjmp in forum C Programming
    Replies: 5
    Last Post: 08-24-2012, 04:35 AM
  3. Replies: 10
    Last Post: 09-24-2010, 01:09 AM
  4. Multiple conditions for the while loop?
    By Olidivera in forum C++ Programming
    Replies: 6
    Last Post: 04-24-2005, 03:47 AM
  5. While Loop Conditions?
    By ted_smith in forum C Programming
    Replies: 8
    Last Post: 01-17-2005, 10:20 PM

Tags for this Thread