Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8975231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:49:31+00:00 2026-06-15T18:49:31+00:00

I made a program just for testing purposes, when you hold the key ‘p’

  • 0

I made a program just for testing purposes, when you hold the key ‘p’ on the keyboard it spills out every day starting from the 1st of January 2012, it should continue on to 2013 and it does although it goes to 32 January 2013, and this is an error which I have no idea how to fix, I’ve been trying to fix this problem for a few hours now and nothing seems to make it work as it should.. (should go to 1st February 2013 after 31st of January)

here is my code:

#include <stdio.h>
#include <stdlib.h>


int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int day = 0;
int year = 2012;

char *months[]=
{
    " ",
    " January ",
    " February ",
    " March ",
    " April ",
    " May ",
    " June ",
    " July ",
    " August ",
    " September ",
    " October ",
    " November ",
    " December "
};


int x = 1; //skip the blank element 0, get to January (element 1)

int main()
{

while(1)
{
    char ch;
    ch = getch(); //in_char();

    if(ch == 'p')
    {
        day++;


        if(day == month[x]+1)
        {
            day = 1; //day is equal to the first day of the new month
            month[x]++; //month data increments
            months[x]++; //month display increments
            x++; //element of month array increments to get the data of the next month


            if(year % 4 == 0) //leapyear
            {
                month[2] = 29;
            }
            else
            {
                month[2] = 28;
            }


            if(x == 13) //if 12 months have passed
            {
                year++; //year increments
                day = 1; //initialize day to be day 1 of the next year
                x = 1; //go back to the 'January' element in the array

                if(day == month[x]) //if day is equal to the first month (January) 31 days
                {
                    day = 1;
                    month[x]++; //month data increments
                    months[x]++; //month display increments
                }
            }
        }
        if(year == 9999)
        {
            year = 1;
        }


        printf("%i%s%04i\n",day,months[x],year);
    }
}


return 0;
}

output:

.
.
.
28 December 2012
29 December 2012
30 December 2012
31 December 2012
1January 2013
2January 2013
3January 2013
4January 2013
5January 2013
6January 2013
7January 2013
8January 2013
9January 2013
10January 2013
11January 2013
12January 2013
13January 2013
14January 2013
15January 2013
16January 2013
17January 2013
18January 2013
19January 2013
20January 2013
21January 2013
22January 2013
23January 2013
24January 2013
25January 2013
26January 2013
27January 2013
28January 2013
29January 2013
30January 2013
31January 2013
**32January 2013**
1February 2013
2February 2013
.
.
.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:49:32+00:00Added an answer on June 15, 2026 at 6:49 pm

    The problem is here:

        if(day == month[x]+1)
        {
            day = 1; // reset date...OKAY
            month[x]++; // NOT OKAY
    

    by doing month[x]++ you are incrementing the number of days allowed in the month. Instead you need to keep a variable to track the month,just as you’ve done with day and year..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made this program just out of interest and wanted to make it better.
I'm a beginner in programming. I've just made a program called Guessing Game. And
I have just started on AWT and made a simple program in it, it
Okay, just learnt LINQ syntax about ten minutes ago, made a first program: public
I have a program I made in C++ that does not use classes, just
I have a report creator program made in Java that needs to run every
I am new to programming, I have made a little program just to learn
I made a simple program which just tracks the co ordinates of the mouse
I made a simple hello world program which just makes a window pop up
so I made a program that creates a registry key on the pc, that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.