Question

In: Computer Science

Write a program in c++ using only if statements that prompts the user to enter an...

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;

}}

Solutions

Expert Solution

#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.


Related Solutions

IN C++ Write a program that prompts the user to enter the number of students and...
IN C++ Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score (display the student’s name and score). Also calculate the average score and indicate by how much the highest score differs from the average. Use a while loop. Sample Output Please enter the number of students: 4 Enter the student name: Ben Simmons Enter the score: 70 Enter the student name:...
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value....
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value. The program should then output a message saying whether the number is positive, negative, or zero.
write a c++ program that prompts a user to enter 10 numbers. this program should read...
write a c++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the two numbers and the average of the 10 numbers PS use file I/o and input error checking methods
( USE C++ ) The program prompts the user to enter a word. The program then...
( USE C++ ) The program prompts the user to enter a word. The program then prints out the word with letters in backward order. For example, if the user enter "hello" then the program would print "olleh" show that it works .
Write a C++ program which prompts the user to enter an integer value, stores it into...
Write a C++ program which prompts the user to enter an integer value, stores it into a variable called ‘num’, evaluates the following expressions and displays results on screen. num+5, num-3, (num+3) – 2, ((num+5)*2 / (num+3)) For performing addition and subtraction, you are allowed to use ONLY the increment and decrement operators (both prefixing and postfixing are allowed). You must remember that using increment/decrement operators changes the original value of a number. Indent your code and include comments for...
C programming. Write a program that prompts the user to enter a 6x6 array with 0...
C programming. Write a program that prompts the user to enter a 6x6 array with 0 and 1, displays the matrix, and checks if every row and every column have the even number of 1’s.
Write a C++ console program that prompts a user to enter information for the college courses...
Write a C++ console program that prompts a user to enter information for the college courses you have completed, planned, or are in progress, and outputs it to a nicely-formatted table. Name the CPP as you wish (only use characters, underscores and number in your file name. DO NOT use blank). Its output should look something like this: Course Year Units Grade ---------- ---- ----- ----- comsc-110 2015 4 A comsc-165 2016 4 ? comsc-200 2016 4 ? comsc-155h 2014...
C++ Write a program that prompts the user to enter 50 integers and stores them in...
C++ Write a program that prompts the user to enter 50 integers and stores them in an array. The program then determines and outputs which numbers in the array are sum of two other array elements. If an array element is the sum of two other array elements, then for this array element, the program should output all such pairs separated by a ';'. An example of the program is shown below: list[0] = 15 is the sum of: ----------------------...
Write a C# program that prompts the user to enter in three values. The first indicates...
Write a C# program that prompts the user to enter in three values. The first indicates a starting (whole number positive) value, the second an ending value and the third an increase value. output a table of squares and square roots, every increase value from the start to the end value. For instance if the values were: start 3, end 20, and increase 4. the table would consist of 3,7,11,15,19 and their squares and square roots. Please include all code...
Write a program In python of Jupiter notebook (using loops) that prompts the user to enter...
Write a program In python of Jupiter notebook (using loops) that prompts the user to enter his/her favorite English saying, then counts the number of vowels in that (note that the user may type the saying using any combination of upper or lower case letters). Example: Enter your favorite English saying: Actions speak LOUDER than words. Number of wovels: 10
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT