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
#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;
}
Comments
Leave a comment