Array Loop Help

Part of my program needs to allow the use to input their birthday in the format MM/DD/YYYY then convert it to the format for example April 6, 2014. I tried this but it didn't work and there's gotta be an easier way to do it.

1
2
3
4
5
6
7
8
9
10
11
printf( "\nYou've chosen to have your birthday converted to a different format.\n"
			"Please enter your birthday in the format MM/DD/YYYY:\t\n" );
			gets( birthday );


			if (birthday[1] == 1)
				{printf("January\n");
			}
			else if (birthday[1] == 6)
				{printf("June\n");
			}
For one thing, birthday[1] will be equal to 1 for January and November. Since you need both the first two digits, you'll need to separate them out. A for loop can do that easily like this:
1
2
3
4
for(int i = 0; i < 2; ++i)
	{
		month += birthday[i];
	}


You're still stuck with a string though so you need to use if/else if instead of a switch. The easiest way though would be to use ints and make the format MM DD YYYY.
Topic archived. No new replies allowed.