Как я могу получить точный вывод следующей программы без использования строки, переключатель.Только «если и еще, если еще» может быть использовано.
Программа:
Write a program 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). Also,
prompt the user to enter the number of days after today for a future day and display
the future day of the week
Правила:
- Ноль равен воскресенью
- Один равен понедельнику
- Три равны вторнику
- четыре равны среде
- пять равны четвергу
- шесть равны пятнице
- Семь равно Сатураде
И пример вывода должен быть:
Enter today's day: 1(press Enter)
Enter the number of days elapsed since today: 3(press Enter)
Today is Monday and the future day is Thursday
Вот мой код:
#include<iostream>
using namespace std;
int main(){
int date,elapsed,day_of_weak,future_date;
cout<<"Enter today's date: ";
cin>>date;
cout<<"Enter the number of days elapsed since today: ";
cin>>elapsed;
//Calculating Future date
future_date = (date+elapsed)%7;
if(date==0){
cout<<"Today is "<<date<<" and the future day is "<<future_date<<endl;
}
if(date==1){
cout<<"Today is "<<date<<" and the future day is "<<future_date<<endl;
}
if(date==2){
cout<<"Today is "<<date<<" and the future day is "<<future_date<<endl;
}
if(date==3){
cout<<"Today is "<<date<<" and the future day is "<<future_date<<endl;
}
if(date==4){
cout<<"Today is "<<date<<" and the future day is "<<future_date<<endl;
}if(date==5){
cout<<"Today is "<<date<<" and the future day is "<<future_date<<endl;
}
if(date==6){
cout<<"Today is "<<date<<" and the future day is "<<future_date<<endl;
}
if(date==7){
cout<<"Today is "<<date<<" and the future day is "<<future_date<<endl;
}
return 0;
}
и мой вывод:
Enter today's date: 1
Enter the number of days elapsed since today: 3
Today is 1 and the future day is 4
Как можно конвертировать 1 в понедельник и 4 в четверг.без использования строк и переключателей.Спасибо