Reputation: 201
so i'm trying to increase the value of that is stored in getDay() by 1 but this method doesn't work. any advice? thanks
if(getDay()<1 || getDay()>31);
{
int temp = getDay();
temp++;
getDay() = temp;
}
Upvotes: 1
Views: 78
Reputation: 11832
You can't update the value returned by getDay()
this way:
getDay() = temp; <-- this won't work
Instead, if a setDay()
method exists, then you could call that:
setDay(temp);
Or, you need to read the code for the getDay()
method and figure out how to set the value in that code.
Edit
So, your code could look like this:
if(getDay()<1 || getDay()>31)
{
int temp = getDay();
temp++;
setDay(temp);
}
Or...
if(getDay()<1 || getDay()>31)
{
int temp = getDay();
setDay(++temp);
}
Upvotes: 2
Reputation: 4251
You can't increase the return value of a function by just assigning a value to it. I think you will need to learn more on functions/methods and how they work.
Upvotes: 1
Reputation: 166
you are using
getDay() = temp;
but that means calling the method and setting the returned value to temp ...or so.
try set the initial value to temp which getDay() handles back. You need to find the value being told by getDay() in the class containing that value and access it directly. sorry for my engl
example: your method:
public int getDay(){return day;}
set method:
public void setDay(int dayPassed){
day= dayPassed;
}
in your example:
if(getDay()<1 || getDay()>31);
{
int temp = getDay();
temp++;
setDay(temp);
}
Upvotes: 2