-1

It usually works but on the 4,6,9 and 11 months at any given date it just skips to the next month on the first day.

#include <iostream>
using namespace std;

int main()
{
    cout << "What is the day after the date you enter?:";
        int day, month, year;
    cin >> day >> month >> year;
    if (day == 31 && month == 12)
    {
        day = 1;
        month = 1;
        year = year + 1;
    }
    else if (day == 31 && month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10)
    {
        day = 1;
        month = month + 1;
    }
    else if (day == 30 && month == 4 || month == 6 || month == 9 || month == 11)
    {
        day = 1;
        month = month + 1;
    }
    else if (day == 28 && month == 2)
    {
        day = 1;
        month = month + 1;
    }
    else if (day == 29 && month == 2)
    {
        day = 1;
        month = month + 1;
    }
    else
    {
        day = day + 1;
    }
    cout << "The day after the date you entered is: " << day << "/" << month << "/" << year << endl;
    return 0;
    system("pause");
}

`

For example, the first date I used was 14 09 2020 and it outputed 1/10/2020

this is a picture for proof

Idk what to do with it please help

Radu
  • 1
  • 1
  • 1
    [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) – Jesper Juhl Nov 16 '22 at 19:36
  • note: noone prevents input of `999 999 999` or displays an error message in this case... (This doesn't have anything to do with the bug in your code though) – fabian Nov 16 '22 at 19:42

1 Answers1

2

You need more brackets

else if (day == 31 && month == 1 || month == 3 || month == 5 ||
    month == 7 || month == 8 || month == 10)

should be

else if (day == 31 && (month == 1 || month == 3 || month == 5 || 
    month == 7 || month == 8 || month == 10))

Same error on the next else if as well.

&& has higher precedence than || so you need brackets to overcome this.

john
  • 85,011
  • 4
  • 57
  • 81