I\'m getting complier errors and I don\'t know for sure how to fix them please l
ID: 673132 • Letter: I
Question
I'm getting complier errors and I don't know for sure how to fix them please look at my program and let me know how I can fix it.
#include <iostream>
#include <string>
using namespace std;
void testMenu();
// postcondition: the test menu is displayed for choose
bool isLeapYear(int year);
// precondition: enter year
// postcondition: year is test to see if its a leap year
int getCenturyValue(int year);
// precondition: enter year
// postcondition: year is given in centuries
int getYearValue(int year);
// precondition: enter year
// postcondition: year is given in value of the year
int getMonthValue(int month, int year);
// precondition: enter year and month
// postcondition: month is given in the month value
int dayofWeek(int month, int day, int year);
// precondition: enter day, month, and year
// postcondition: day is given in what day of the week it is
string dayofWeek(int day);
//precondtion: day has integer value 0, 1, 2, 3, 4, 5, or 6
//postcondtion: the name of the day of week is returned as a string
// If day has value 0, then Sunday is returned; 1, then Monday is returned and so on
int main()
{
int choice;
int day, month, year;
do {
testMenu();
cout << "Please choose from menu: ";
cin >> choice;
switch (choice)
{
case 1: // check if a given year is leap year
cout << "Please enter a year: ";
cin >> year;
if (isLeapYear(year))
cout << "Year " << year << " is a leap year" << endl;
else
cout << "Year " << year << "is NOT a leap year" << endl;
break;
case 2: // calculate the century value of a given year
cout << "Please enter a year: ";
cin >> year;
cout << "The century vaule is: " << getCenturyValue(year) << endl;
break;
case 3: // calculate the year value of a given year
cout << " Please enter a year: ";
cin >> year;
cout << "The year vaule is: " << getYearValue(year) << endl;
break;
case 4: // calculate the month value of a given month is a given year
cout << "Please enter a year and month: ";
cin >> year >> month;
cout << "The month value is: " << getMonthValue(month, year) << endl;
break;
case 5: // calculate the day of week of given date
cout << "Please enter a year, a month and a day: ";
cin >> year >> month >> day;
cout << "The day of the week is: " << dayofWeek(month, day, year) << endl;
break;
case 6: // print out the name of a given day of week
cout << "Please enter a day week (0 for Sunday, 1 for Monday, etc): ";
cin >> day;
cout << "The name of the day of the week is: " << dayofWeek(day) << endl;
break;
case 7:
cout << "Did you tested all functions yet? if not, please rerun the program ";
break;
default:
cout << "Wrong option. Please choose from menu ";
break;
}
system("pause");
} while (choice != 7);
}
void testMenu()
{
cout << " ***************************************************";
cout << " * Menu *";
cout << " * 1. Check if year is a leap year *";
cout << " * 2. Calculate the century value *";
cout << " * 3. Calculate the year value *";
cout << " * 4. Calculate the month value *";
cout << " * 5. Calculate the day of the week *";
cout << " * 6. Print out the name of the day of the week *";
cout << " * 7. Check if you test all functions *";
cout << " ***************************************************";
}
bool isLeapYear(int year)
{
year % 4 == 0 || year % 400 == 0 || year % 100 == 0;
}
int getCenturyValue(int year)
{
int year1, total1, total;
year1 = year / 100;
total1 = year1 % 4;
total = 3 - total1;
return (total * 2);
}
int getYearValue(int year)
{
int year1, year2, total1, total;
year1 = year / 100;
year2 = year - (year1 * 100);
total1 = year2 / 4;
return (total + year2);
}
int getMonthValue(int month, int year)
{
int value = 0;
if (isLeapYear(year))
{
switch (month)
{
case 1:
value = 6;
break;
case 2:
value = 2;
break;
}
}
else
{
switch (month)
{
case 1:
value = 0;
break;
case 2:
value = 3;
break;
case 3:
value = 3;
break;
case 4:
value = 6;
break;
case 5:
value = 1;
break;
case 6:
value = 4;
break;
case 7:
value = 6;
break;
case 8:
value = 2;
break;
case 9:
value = 5;
break;
case 10:
value = 0;
break;
case 11:
value = 3;
break;
case 12:
value = 5;
break;
default:
value = 0;
}
}
int dayofWeek(int day)
{
int total1;
total1 = (day + getMonthValue + getYearValue + getCenturyValue) % 7;
}
string dayofWeek(int day)
{
int total1;
string total;
total1 = (day + getMonthValue + getYearValue + getCenturyValue) % 7;
switch (total1)
{
case 0:
total = " Sunday ";
break;
case 1:
total = " Monday ";
break;
case 2:
total = " Tuesday ";
break;
case 3:
total = " Wednesday ";
break;
case 4:
total = " Thursday ";
break;
case 5:
total = " Friday ";
break;
case 6:
total = " Saturday ";
break;
}
Explanation / Answer
You can fix the problems specified as given below:
First, include the header file ‘cstdlib’ i.e., #include <cstdlib> to fix the error ‘system was not declared in this scope’
Second, You can't put the function definition inside another function (main() is also a function). i.e., int dayofWeek(int day) is defined in the main()
Finally, You can't put the function definition inside another function (main() is also a function). i.e., string dayofWeek(int day) is defined in the main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.