need help with functions

i am working a problem and i'm having trouble wrapping my head around a bool function, i need help. here is the problem.
Write a function that returns number of days in a year using the following header.
int numberOfDaysInAYear(int year)



#include<iostream>
#include<iomanip>
using namespace std;




bool leapYear(int year)
{
if ((year % 4 != 0 && year % 100 == 0) || (year % 400 != 0))
{

return false;
}
else
return true;
}
int nd(int year)
{
if (true)
cout<<"366";


else
cout<<"365";
return 0;
}
int main(){
// bool leapyear;
cout<<"year"<<setw(10)<<"#"<<setw(9)<<"days"<<endl;
cout<<"-----------------------------------"<<endl;
int year = 2000;
for (int year = 2000; year<=2010; year++)
{
cout<< year <<setw(10)<<"="<<setw(8)<< leapYear(2000)<< endl;
}
//nd(year >=2000 && year <=2010);
system("pause");
return 0;}
¿what's your issue?
In your function int nd, if (true) is where I spot the problem. Use if(year) or if (year==true)( and return 0?) since year is a boolean type. And since int nd is returning nothing other than printing an output, you may wanna change it †☺ void nd.
Last edited on
Instead of if (true) use if (leapYear(year)).
thanks for the help, i screwed the pooch a little when posting though. i was working a couple programs at once. that wasn't the program i was having trouble with, sorry. the program i was having trouble with is this one.
// problem using an array

#include<iostream>
using namespace std;

int main()
{
const int SIZE = 10;
double earnings[SIZ];
const int STOP = 99;
double amt;
int person;
cout << "Enter sales made by any of our ten salespeople" << endl <<
"Their sales numbers are digits 1 through 10" << endl <<
"You can enter as many money amounts as you want " << endl <<
"for each person in any order" << endl;
cout << "Enter salesperson number 1 - " << SIZE << ". Enter " << STOP << " to quit. ";
cin >> person;
while(person = STOP)
{
if(person >= 1 && person <= 10)
{
cout << "Enter the sale amount ";
cin >> amt;
earnings[person-1] += amt;
}
else
cout << "Number out of range. Please enter another" << endl;
cout << "Enter another salesperson number 1 - SIZE or STOP to quit ";
cin >> person;
}
cout << endl << "Salesperson totals are:" << endl;
for(person = 0; person < SIZE; --person)
cout << "Salesperson " << (person + 1) << " $" << earnings[person] << endl;
return 0;
}
Last edited on
Topic archived. No new replies allowed.