Generating Sequential Numbers

+1 Andrew Martin · July 6, 2015



I'm trying to Assign a call number that contains the year, two digit representation of the month and a 
sequential number starting from 1. An example of this would be call number, 2006-05-1. Can anyone write a code that can solve this mystery as i'm confused to how a string and an integer can be used to count. Thank You all :-) 

P.s I just started programming 2 months ago!!!!

Post a Reply

Replies

Oldest  Newest  Rating
+1 Hyun Choi · July 10, 2015

int main()
{
    int year, num = 1; // num is the counter

    printf("Press 0 when done\n\n");
   
   do{
   
printf("\nEnter year: ");
    scanf("%d", &year);

if(year == 0) //terminates the program
    {
       continue;
    }
   
char month[3];
    printf("Enter month: ");
    scanf("%s", month);
   
if(month[0] != '1') // adds the 0 if the month is < 10
    {
        month[1] = month[0];
        month[0] = '0';
    }
   
printf("%d-%s-%d\n", year, month, num);
    num++;
    } while(year != 0);

    return 0;
}
  • 1

C

107,111 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator