In: Computer Science
Write a program in c++ using only if statements that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is 1 …., and Saturday is 6) then displays today. Also, prompt the user to enter the number of days after today for a future day and display the future day of the week.
The future day can be computed as follows:
(today + number of days after today) % 7
Sample run 1:
Enter today's day (Sunday is 0, Monday is 1 ..., and Saturday is 6): 1
Today is Monday.
Enter the number of days elapsed since today: 31
The future day is Thursday.
Sample run 2:
Enter today's day (Sunday is 0, Monday is 1 ..., and Saturday is 6): 10
Invalid number ...
--
--
how can i fix my code:
#include
using namespace std;
int main()
{
int day, num;
cout<<"Enter today's day (Sunday is 0, Monday is 1 ..., and Saturday is 6): ";
cin>> day;
if(day==0)
{
cout << "Today is Sunday." << endl;
}
else if(day==1)
{
cout << "Today is Monday." << endl;
}
else if(day==2)
{
cout << "Today is Tuesday." << endl;
}
else if(day==3)
{
cout << "Today is Wenesday." << endl;
}
else if(day==4)
{
cout << "Today is Thursday." << endl;
}
else if(day==5)
{
cout << "Today is Friday." << endl;
}
else if(day==6)
{
cout << "Today is Saturday." << endl;
}
else
{
cout << "Invalid number ..." << endl;
}
cout << "Enter the number of days elapsed since today: ";
cin >> num;
int futureday = ((day+num)%7);
if(futureday==0)
{
cout<<"The future day is Sunday." << endl;
}
else if(futureday==1)
{
cout<<"The future day is Monday." << endl;
}
else if(futureday==2)
{
cout<<"The future day is Tuesday." << endl;
}
else if(futureday==3)
{
cout<<"The future day is Wenesday." << endl;
}
else if(futureday==4)
{
cout<<"The future day is Thursday." << endl;
}
else if(futureday==5)
{
cout<<"The future day is Friday." << endl;
}
else
{
cout<<"The future day is Saturday." << endl;
return 0;
}}
#include<iostream>
using namespace std;
int main()
{
int day, num;
int flag=0;
cout<<"Enter today's day (Sunday is 0, Monday is 1 ..., and
Saturday is 6): ";
cin>> day;
if(day==0)
{
cout << "Today is Sunday." << endl;
}
else if(day==1)
{
cout << "Today is Monday." << endl;
}
else if(day==2)
{
cout << "Today is Tuesday." << endl;
}
else if(day==3)
{
cout << "Today is Wenesday." << endl;
}
else if(day==4)
{
cout << "Today is Thursday." << endl;
}
else if(day==5)
{
cout << "Today is Friday." << endl;
}
else if(day==6)
{
cout << "Today is Saturday." << endl;
}
else
{
cout << "Invalid number ..." << endl;
flag=1;//set flag to 1 if invalid entry is occurred
}
if(flag==0){
cout << "Enter the number of days elapsed since today:
";
cin >> num;
int futureday = ((day+num)%7);
if(futureday==0)
{
cout<<"The future day is Sunday." << endl;
}
else if(futureday==1)
{
cout<<"The future day is Monday." << endl;
}
else if(futureday==2)
{
cout<<"The future day is Tuesday." << endl;
}
else if(futureday==3)
{
cout<<"The future day is Wenesday." << endl;
}
else if(futureday==4)
{
cout<<"The future day is Thursday." << endl;
}
else if(futureday==5)
{
cout<<"The future day is Friday." << endl;
}
else
{
cout<<"The future day is Saturday." << endl;
return 0;
}
}
else{
cout<<"--"<<endl;
cout<<"--"<<endl;
}
}
Screenshots:
The screenshots are attached below for reference.
Please follow them for output.
Please upvote my answer. Thank you.