When i choose 4 mars why does it start at 0.4992 and not 49.92 what do i do?
Solution 1:
You should use either fractions (say * 0.39
) or per cents (* 39) / 100
), but not a combination:
Your code amended:
static double convert(int choice, double on_earth)
{
double on_planet = 0;
if (choice == 1)
on_planet = (on_earth * 0.38);
else if (choice == 2)
on_planet = (on_earth * 0.78);
else if (choice == 3)
on_planet = (on_earth * 1.0);
else if (choice == 4)
on_planet = (on_earth * 0.39);
else if (choice == 5)
on_planet = (on_earth * 2.65);
else if (choice == 6)
on_planet = (on_earth * 1.17);
else if (choice == 7)
on_planet = (on_earth * 1.05);
else if (choice == 8)
on_planet = (on_earth * 1.23);
return on_planet;
}
A better choice is to extract model:
// With model extracted it's much easier to see the wrong figures
static double[] s_OnPlanets = new double[] {
0.38, 0.78, 1.00, 0.39, 2.65, 1.17, 1.05, 1.23
};
// Now we have no need in that many ifs:
static double convert(int choice, double on_earth) =>
s_OnPlanets[choice - 1] * on_earth;