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!

4
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by tetron

Do you have a question?
Are you having a problem?
What do you need help with?

hello, i have been struggling with this program for a few days now, and have decided to get some feedback.
* * * *
If anyone has any questions on any of my code or program description please let me know. Thanks!

Why would we have questions? I think it's much more important if you have questions. And if so, ask them.

If you posted this because you are having problems, we are not the Psychic Programming Network. You need to tell us what you need.

my bad..i keep getting error messages saying that i need a primary expression before the or symbol ||. Also, an error occurs saying i cannot convert std::string to int. any help on how i could fix these?

1) Post the EXACT error message. Many time the paraphrased error is missing pertinent -- like line numbers.

2) found the first error -- you forgot to put () around the `if` comparison. You have them only around the terms, not the entire comparison.

3) No, a `string` and `int` are not the same. Just like you can't make pudding out of a rock. Find out where the error is and decide what you are trying to do. Then figure out a way to accomplish that desire.

First at some point you need to add the method for getting the user's input.

Your if loop is wrong because you should be using `==` to see if something is the same as something else
and this gives either `true` or `false` and if it is true the if will execute the code inbetween the {}
or the line following it.

there for when you say

``````else if(start_day = 1)//sets starts day to one and acts as >0 = true
day == "Monday";//this line does nothing``````

If you are being confused by this code try writing it in reverse

``````if(1 == start_day)//with single = this gives an error
{
day = "Monday";//with  == this gives a warning
}``````

The other question is do you want to check

``````if(day == "Monday")
{
start_day = 1;
}``````

line 35 does nothing
line 39 you cannot put a string directly in an int

this is very higgledy-piggledy and you need to think about what you want to do at each stage and what information the computer needs to do things also if you have done functions this might help you clear-up the ordering of things

until you do the input it is not clear your intention

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!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.