Dec 9, 2013 at 7:19am UTC
Hello, yeah I am trying to work on program and I feel like there could be a better way of writing this? I am Trying to learn good techniques.t
Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
if (haul >= bestHP) {
if (haul == bestHP) {
if (theDistance > bestDistance) {
bestA = coordinateA;
bestB = coordinateB;
bestC = coordinateC;
bestDistance = theDistance;
bestHP = haul;
bestPlanet = planetName;
}
}
bestA = coordinateA;
bestB = coordinateB;
bestC = coordinateC;
bestDistance = theDistance;
bestHP = haul;
bestPlanet = planetName;
}
Last edited on Dec 9, 2013 at 7:58am UTC
Dec 9, 2013 at 7:26am UTC
Thank you much appreciated, I didn't know they were similar.
Dec 9, 2013 at 7:59am UTC
I added one more quick question if anyone knows the answer to it.
Dec 9, 2013 at 8:12am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
if (haul >= bestHP)
{
if (haul == bestHP && theDistance > bestDistance)
{
bestA = coordinateA;
bestB = coordinateB;
bestC = coordinateC;
bestDistance = theDistance;
bestHP = haul;
bestPlanet = planetName;
}
bestA = coordinateA;
bestB = coordinateB;
bestC = coordinateC;
bestDistance = theDistance;
bestHP = haul;
bestPlanet = planetName;
}
Last edited on Dec 9, 2013 at 8:12am UTC
Dec 9, 2013 at 10:45am UTC
What is the point of lines 2 - 11 in the OP (or 3 - 11 in Mats' reworking)? What do they achieve that isn't being done anyway in lines 12 - 17? The entire thing could be written as:
1 2 3 4 5 6 7 8 9
if (haul >= bestHP)
{
bestA = coordinateA;
bestB = coordinateB;
bestC = coordinateC;
bestDistance = theDistance;
bestHP = haul;
bestPlanet = planetName;
}
Is this a homework question?
Last edited on Dec 9, 2013 at 10:46am UTC
Dec 9, 2013 at 8:44pm UTC
no I am writing a program. This is my first language and I am working on trying to simplify and edit my code. Now that I know what needs to be done I need to work on simplifying my code.
Dec 9, 2013 at 8:48pm UTC
I put your code and replaced it with mine MikeyBoy. I think it was late when I was coding this, as my code was just crappy logic. Thank you.