Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Running into a problem with a string statement in my calendar c++ program. It says the operator <

Running into a problem with a string statement in my calendar c++ program. It says the operator "<<" doesnt match any operands right before my string variable monthName. Please take a look, i have wrote comments and bolded the appropriate sections in my code. Thank you!

#include

using namespace std;

// declarations

void printMonth(int year, int month, int dayOfWeek);

bool isLeapYear(int year);

int main()

{

//variables

int getFirstDay;

int year;

//Year

cout << "What year do you want a calendar for?";

cin >> year;

// 1st day of week

while (true)

{

cout << "What day of the week does January 1 fall on (0 for Sunday, 1 for Monday, etc.)?";

cin >> getFirstDay;

if (getFirstDay < 0 || getFirstDay > 6)

{

cout << ":: Invalid Day.Enter Valid number between 0 and 6 ::" << endl;

continue;

}

else

break;

}

for (int i = 1; i <= 12; i++)

{

printMonth(year, i, getFirstDay);

}

return 0;

}

void printMonth(int year, int month, int getFirstDay)

{

int days = 0;

// string variable monthName

string monthName = " ";

//switch for Month Name

switch (month)

{

case 1:

monthName = "January";

days = 31;

break;

case 2:

monthName = "February";

if (isLeapYear(year))

{

days = 29;

}

else

{

days = 28;

}

break;

case 3:

monthName = "March";

days = 31;

break;

case 4:

monthName = "April";

days = 30;

break;

case 5:

monthName = "May";

days = 31;

break;

case 6:

monthName = "June";

days = 30;

break;

case 7:

monthName = "July";

days = 31;

break;

case 8:

monthName = "August";

days = 31;

break;

case 9:

monthName = "September";

days = 30;

break;

case 10:

monthName = "October";

days = 31;

break;

case 11:

monthName = "November";

days = 30;

break;

case 12:

monthName = "December";

days = 31;

break;

default:

cout << "Invalid Month.";

exit(0);

break;

}

/* This is where i am running into the problem the 1st "<<" operator has a squigglly

line under it saying no operator matches these operands before the string variable

monthName */

cout << " " << monthName << " " << year << endl;

cout << "__________________________________" << endl;

cout << " Sun Mon Tue Wed Thu Fri Sat" << endl;

int i = 0;

int firstDay = 0;

switch (month)

{

case 1:

firstDay = getFirstDay;

break;

case 2:

firstDay = getFirstDay + 3;

break;

case 3:

firstDay = getFirstDay + 3;

break;

case 4:

firstDay = getFirstDay + 6;

break;

case 5:

firstDay = getFirstDay + 8;

break;

case 6:

firstDay = getFirstDay + 11;

break;

case 7:

firstDay = getFirstDay + 13;

break;

case 8:

firstDay = getFirstDay + 16;

break;

case 9:

firstDay = getFirstDay + 19;

break;

case 10:

firstDay = getFirstDay + 21;

break;

case 11:

firstDay = getFirstDay + 24;

break;

case 12:

firstDay = getFirstDay + 26;

break;

}

if (isLeapYear(year))

{

switch (month)

{

case 1:

firstDay = getFirstDay;

break;

case 2:

firstDay = getFirstDay + 3;

break;

case 3:

firstDay = getFirstDay + 4;

break;

case 4:

firstDay = getFirstDay + 7;

break;

case 5:

firstDay = getFirstDay + 9;

break;

case 6:

firstDay = getFirstDay + 12;

break;

case 7:

firstDay = getFirstDay + 14;

break;

case 8:

firstDay = getFirstDay + 17;

break;

case 9:

firstDay = getFirstDay + 20;

break;

case 10:

firstDay = getFirstDay + 22;

break;

case 11:

firstDay = getFirstDay + 25;

break;

case 12:

firstDay = getFirstDay + 27;

break;

}

}

int dayOfWeek = 0;

if ((firstDay % 7) >= 0)

{

if ((firstDay % 7) == 0)

{

dayOfWeek = 0;

}

else if ((firstDay % 7) == 1)

{

dayOfWeek = 1;

cout << " ";

}

else if ((firstDay % 7) == 2)

{

dayOfWeek = 2;

cout << "\t ";

}

else if ((firstDay % 7) == 3)

{

dayOfWeek = 3;

cout << "\t\t";

}

else if ((firstDay % 7) == 4)

{

dayOfWeek = 4;

cout << "\t\t ";

}

else if ((firstDay % 7) == 5)

{

dayOfWeek = 5;

cout << "\t\t\t";

}

else if ((firstDay % 7) == 6)

{

dayOfWeek = 6;

cout << "\t\t\t ";

}

}

for (i = 1; i <= days; i++)

{

if (i < 10)

cout << " " << i;

else

cout << " " << i;

if ((i + firstDay) % 7 == 0)

cout << endl;

}

cout << endl;

}

// leap year function

bool isLeapYear(int year)

{

if (year % 400 == 0) {

return true;

}

if (year % 100 == 0) {

return false;

}

if (year % 4 == 0) {

return true;

}

return false;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions

Question

Explain why it is important to measure customer retention.

Answered: 1 week ago