Okay here is my program, it has only two compiles errors: C2659: '=' : function as left operand. I'm new to C++ and get confused by this error, can anyone correct my program? Thanks. Here is the program:
#include %26lt;iostream%26gt;
#include %26lt;cstdlib%26gt;
using namespace std;
int getYear();
bool isLeap(int year);
char moreData();
int main()
{
int year;
char carryOn='y';
while(carryOn=='y'||carryOn=='Y'){
year=getYear();
if(isLeap(year)){
cout%26lt;%26lt;" is a leap year\n";
}else{
cout%26lt;%26lt;" is not a leap year\n";
}
carryOn=moreData();
}
system("pause");
}
int getYear(){
int year;
cout%26lt;%26lt;"Enter a year: ";
cin%26gt;%26gt;year;
return year;
}
bool isLeap(int year){
if(year%4==0){
if (year%100!=0){
isLeap=true;
}else if (year%400==0){
isLeap=true;
}
//return isLeap;
}}
char moreData(){
char carryOn;
cout%26lt;%26lt;"Do you want to enter more data? (y/n) ";
return carryOn;
}
C++ Leap Year Program with error C2659: '=' : function as left operand problem?
in your isLeap() function.. you are assigning isLeap=true.... which cannot be done.. because isLeap is the pointer to the function isLeap().. dont worry if you dont understand that..... But you can use the statement
return (true);
instead of
isLeap=true;
and use the statement
return(false);
at the end of the isLeap function just before the closing flower brace.. that will make the program work...
Reply:I think your
isLeap=true;
statements need to be
return true;
instead!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment