Answer to Question #332691 in C++ for Joshua Lee

Question #332691

Write a program that prompts the user to enter the day number of a week and hours passed, and displays the day and remaining hours. For example, if the user entered day number 2 and hours passed 4, the program should display Today is Monday and Remaining Hours: 20. If the user entered day number 7 and hours passed 12, the program should display Today is Saturday and Remaining Hours: 12

1
Expert's answer
2022-04-23T03:21:52-0400
#include <iostream>
using namespace std;

int main() {
    int day, hours;
    string weekDay[7]={"Sunday","Monday","Tuesday","Wenesday","Thursday","Friday","Saturday"};

    cout<<"Enter the day number of a week: ";
    cin>> day;
    
    if(day<1||day>7){
        cout << "Invalid number ..." << endl;
        return 1;
    }
    else{
         cout<<"Enter the hours passed: ";
        cin>>hours;
        if(hours<0||hours>24){
            cout << "Invalid number ..." << endl;
            return 1;
            }
        else {
            cout<<"Today is "<<weekDay[day-1]
            << "  remaining hours: "<<24-hours<<endl;
        }
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS