1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream.h>
#include <conio.h>
#include<stdio.h>
void main()
{
clrscr();
int i,j,mm; char month[3], conststring[12][3]={'J','a','n',
'F','e','b',
'M','a','r',
'A','p','r',
'M','a','y',
'J','u','n',
'J','u','l',
'A','u','g',
'S','e','p',
'O','c','t',
'N','o','v',
'D','e','c'};
/*You need not to make array of full names of month.
Let the user enter January but the program reads only Jan and gives 1*/
cout<<"Enter a month: "; gets(month);
for(mm=0;mm<12;mm++)
{ for(i=0,j=0;j<3;j++)
if(month[j]==conststring[mm][j]) i++;
if(i==3) {mm++; break;}
}
cout<<"The month you have entered is: "<<mm;
getch();
}
|