What im trying to do is have the program to run the first set of numbers. Then Use output as ‘X’. So it looks like this
Tnew = Told – m(Told – Tair)
Told is the last equations Tnew.
ex. new = old +6
old = 7
new = 13
new = 13 +6
repeat
Heres the code ;
package heatloss;
/**
*
* @author Eric Franzen
*/
public class HeatLoss {
public static void heatloss(double x, double m, double a) {
double heatloss = x - m * (x - a);
if (x < 55) {
System.out.println("potatoe too cold");
}
else {
System.out.println(heatloss);
heatloss(x,m,a);
x = heatloss;
}
}
public static void main(String[] args) {
heatloss(80, .01515 ,25);
}
}
Okay so I changed the code to look like this:
public static double heatloss(double x, double m, double a) {
double heatloss = x - m * (x - a);
if (x < 55) {
System.out.println("potatoe too cold");
return heatloss;
}
else {
System.out.println(heatloss);
x = heatloss(x,m,a);
return heatloss;
}
}
But I get an error at line
x = heatloss(x,m,a);
That “the Assigned value is never used.”
Im not really sure what that means? X is clearly used in the program.
In order for one invocation of a recursive method to access data inside of another (for example, data stored in local variables), you need to somehow communicate that data out of the second recursive call into the first. In this case, you might want to consider having the
heatlossmethod return the value of theheatlosslocal variable. For example:By filling in the appropriate blanks (I’m not sure how you’d do that here, since I’m not familiar with the particular problem you’re solving), you should be able to communicate information out of the deeper calls into the higher-up calls.
Hope this helps!