Pic. reference - http://41.media.tumblr.com/ec1e2865d914521ded388fbcc447791c/tumblr_inline_nu6vqczp8y1tbt8rv_400.png
#include<stdio.h> //Start Program
void main()
{
int date,elapsed_days,future_day; //Declare the variables.
printf("Enter an integer for today date of week = "); //Ask the user to enter integer for today.
scanf("%d", &date);
if (date < 7) //There are 7 days in week, if user inputs wrong, it should show an error message.
{
printf("Enter the number of days since elapsed today = "); //Input the days elasped since today.
scanf("%d", &elapsed_days);
future_day = (date + elapsed_days) % 7; //Find Future day.
switch (date) //Print the message according to input.
{
case 0: // Two ways of writing program are switch and with if else.
printf("Today is Sunday");
break;
case 1:
printf("Today is Monday");
break;
case 2:
printf("Today is Tuesday");
break;
case 3:
printf("Today is Wednesday");
break;
case 4:
printf("Today is Thursday");
break;
case 5:
printf("Today is Friday");
break;
case 6:
printf("Today is Saturday");
break;
default:
printf("Invalid Input.");
break;
}
if (future_day == 0) //Print the future day according to user input.
printf(" and Future day is Sunday.");
else if (future_day == 1)
printf(" and Future day is Monday.");
else if (future_day == 2)
printf(" and Future day is Tuesday.");
else if (future_day == 3)
printf(" and Future day is Wednesday.");
else if (future_day == 4)
printf(" and Future day is Thursday.");
else if (future_day == 5)
printf(" and Future day is Friday.");
else if (future_day == 6)
printf(" and Future day is Saturday.");
}
else //Otherwise ask the user to input right integer.
printf("Please enter the valid number.");
getch();
} //EndProgram.
Comments
Post a Comment