Я начинаю изучать, как использовать C ++, и в настоящее время пытаюсь подсчитать, в какой день столетия наступил день, когда они запускают мою программу. Я получаю сообщение об ошибке, но при поиске ошибки появляется сообщение, что выводить нечего. Я использую unix в своем терминальном приложении в ma c os, поэтому я не уверен, влияет ли это на что-нибудь. Я много раз проходил свою программу с белой доской и все еще заблудился. Большое спасибо за просмотр моего вопроса.
Ошибка:
lab6.cpp: In function 'int day_of_century(int, int, int)':
lab6.cpp:80:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
Код:
#include <library.h>
//global variables:
int month = 0;
int year = 0;
int day = 0; //this day variable is for getting the day for a date
int days = 0;//this days variable is for counting an amount of days
int count = 1;
//functions:
int length_of_month(int month, int year) {
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
cout << "31 Days" << endl;
}//31 day if
if (month == 4 || month == 6 || month == 9 || month == 11) {
cout << "30 Days" << endl;
}//30 day if
if (month == 2) {
if (year % 400 == 0 && year % 100 == 0) {
cout << "29 Days" << endl;
}//29 day if 1
else if (year % 4 == 0 && year % 100 == 0) {
cout << "28 days" << endl;
} // 28 days 1
else if (year % 4 == 0) {
cout << "29 days" << endl;
} // 29 days 2
else {
cout << "28 Days" << endl;
}//28 day else
}//february
return(0);
}
int length_of_month_value(int month, int year) {
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
days = 31;
}//31 day if
if (month == 4 || month == 6 || month == 9 || month == 11) {
days = 30;
}//30 day if
if (month == 2) {
if (year % 400 == 0 && year % 100 == 0) {
days = 29;
}//29 day if 1
else if (year % 4 == 0 && year % 100 == 0) {
days = 28;
} // 28 days 1
else if (year % 4 == 0) {
days = 29;
} // 29 days 2
else {
days = 28;
}//28 day else
}//february
return(days);
}
int day_of_year(int year, int month, int days) {
if (month == 1) {
days = day;
}//if
else {
while (count < month) {
days = days + length_of_month_value(count, year);
count = count + 1;
}//while
// days = day + days;
}//else
return(days);
}
int day_of_century(int year, int month, int days) {
if (year == 2000) {
return(day_of_year(year, month, days));
}
else if (year > 0) {
return(day_of_year(year - 1, 12, 31) + day_of_century(year - 1, month, days));
}
}
int day_of_century(int year, int month, int days) {
}
//main function:
int main() {
//1: Length of Month:
cout << "Please enter the month (numerically) with the year (numerically) and this program will tell you how many days are in that month" << endl;
cout << "Month: ";
cin >> month;
cout << endl << "Year: ";
cin >> year;
cout << endl;
length_of_month(month, year);
cout << endl;
//2: Day of the Year:
year = 0;
month = 0;
days = 0;
day = 0;
cout << "Please enter the year, month, and day, and this program will tell you what day of the year that date is." << endl;
cout << "Year: ";
cin >> year;
cout << endl << "Month: ";
cin >> month;
cout << endl << "Day: ";
cin >> day;
cout << "You are in day " << day_of_year(year, month, day) << " of the year." << endl;
// day_of_year(year, month, day);
// cout << days+day;
cout << endl;
//3: Day of the Century:
year = 0;
month = 0;
days = 0;
day = 0;
count = 1;
cout << "Please enter the year, month, and day, and this program will tell you what day of the century that date is in. This program only stays in this current century so please pick a year between 2000 and 2099." << endl;
cout << "Year: ";
cin >> year;
cout << endl << "Month: ";
cin >> month;
cout << endl << "Day: ";
cin >> day;
cout << "You are in day " << day_of_century(year, month, day) << " of the century." << endl;
return(0);
}