In this program, I am trying to have it input a day of the week from the user and then a number of days in advance and the program will output the day of the week that number of days later.
The problem I have is that I have 8 errors that are all basically the same thing: that I can't convert from 'const char[#]' to 'char[20]'
Here is the code I have right now:
// Tymon Scott
#include
<iostream>using
namespace std;int
main(){
char day[20], DAY[20]; int numdays, num, day1, day2;cout <<
"What day of the week is it ";cin >> day;
if ( day == "Sunday" || day == "sunday" ){
day1 = 1;
}
else if ( day == "Monday" || day == "monday" ){
day1 = 2;
}
else if ( day == "Tuesday" || day == "tuesday" ){
day1 = 3;
}
else if ( day == "Wednesday" || day == "wednesday" ){
day1 = 4;
}
else if ( day == "Thursday" || day == "thursday" ){
day1 = 5;
}
else if ( day == "Friday" || day == "friday" ){
day1 = 6;
}
else if ( day == "Satruday" || day == "saturday" ){
day1 = 7;
}
cout <<
"How many days in advance of today do you want to know ";cin >> numdays;
num = numdays % 7;
if ( num == 0 ){
day2 = day1;
}
else if ( num == 1 ){
day2 = day1 + 1;
}
else if ( num == 2 ){
day2 = day1 + 2;
}
else if ( num == 3 ){
day2 = day1 + 3;
}
else if ( num == 4 ){
day2 = day1 + 4;
}
else if ( num == 5 ){
day2 = day1 + 5;
}
else if ( num == 6 ){
day2 = day1 + 6;
}
if ( day2 == 1 ){
"Sunday.";DAY =
}
else if ( day2 == 2 )
{
DAY = "Monday.";
}
else if ( day2 == 3 )
{
DAY = "Tuesday.";
}
else if ( day2 == 4 )
{
DAY = "Wednesday.";
}
else if ( day2 == 5 )
{
DAY = "Thursday.";
}
else if ( day2 == 6 )
{
DAY = "Friday.";
}
else if ( day2 == 7 )
{
DAY = "Saturday.";
}
else
{
"undeterminable.";DAY =
}
cout <<
"The day that is "<<numdays<<" days after today is: "<<DAY; return 0;}
PS: is there a way to post code on here without having it all spaced out and formatted correctly and all that stuff

problem with code -- help
vooroojak
For comparing strings of characters in native C++, you can't use == or = for assigning. You need to use the functions strcmp & strcpy. For more details, check the docs for such methods and how to use them.
I would really advise you to read a little bit about the C++ language since these are basics of the language. I wouldn't depend on the forums to learn the language.
Thanks, Ayman Shoukry VC++ TeamBalajiArun
Thank-you.
Sorry, I'm just learning the language.
jmbillings
I second Ayman's recommendation. It would be good to start with a text on C/C++ and work through some examples. There are some very non-obvious things about C/C++ that it takes some struggling with.
There are a great number of lessons in your attempt here and I suspect that you will gain a lot making improved versions to work.
As a tip, you need to know that day by itself does not refer to the array day[ ], but is a pointer to the first element (day[0]). Comparing pointers is not the same as comparing the contents.
As a second tip, which also involves getting deep into the subtleties about string constants and arrays of characters and pointers to arrays of characters, you should look around until you find something about why
might eventually work better in what you are doing. (I just stumbled over that in a book while looking up something else. It is really important to know where to look up explanations of how the language works and to test your understanding of it with little programs that run.) This is not a free fish. The thing to learn is why this might be useful in your program (and by then you will probably figure out a much tighter way to have done the whole thing).
Have fun! There are lots of odd little things that will rock your world until you become accustomed to the way the language works. And there are lots of great approaches to learn once you get some basic understanding.
IBBoard
Thank-you very much.
That solved [one of] my problem
instantly. I'm just taking a class on C++ now and I'm in my first year of learning the language. This is one of my homework problems. Now I just have to figure out how to check if a string is equal to "Monday"....
Thanks again!