hello, i have been struggling with this program for a few days now, and have decided to get some feedback. The program lets the user input a number from 0-6 (0 representing sunday and 6 representing saturday, and so on) for days of the week and you input a second number from 1-366, for the day of the year. My instructor gave us 1 formula to calculate the number of the day of the week which is:
(start day + day of year - 1) % 7
Here is an example of how input/ output should be:
Enter the start day (0-6): 0
Enter the day of the year (1-366): 9
9th day is Monday.
Here is my code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int startday;
int dayofyear;
string day;
string day2;
day2 = "Invalid day of the year!";
if (startday = 0)
day == "Sunday";
else if (startday = 1)
day == "Monday";
else if (startday = 2)
day == "Tuesday";
else if (startday = 3)
day == "Wednsday";
else if (startday = 4)
day == "Thursday";
else if (startday = 5)
day == "Friday";
else if (startday = 6)
day == "Saturday";
else if (startday < 0) || (startday > 6)
day == "Invalid start day!";
if (dayofyear >= 1) || (dayofyear <= 366)
{
dayofyear = dayofyear;
}
else
{
dayofyear = day2;
}
cout << "Enter the start day (0-6): " << endl;
cin >> startday;
cout << "Enter the day of the year: " << endl;
cin >> dayofyear;
startday = (startday + day of year - 1) % 7;
startday = startday;
cout << dayofyear << "day is " << startday << endl;
return 0;
}
If anyone has any questions on any of my code or program description please let me know. Thanks!