I apologize for asking such a newbie question, but this is my first class in programming in "C" and this program is unfortunately due today. I have no experience at all in doing this and cannot figure out how to fix this warning I am getting.
I am getting:
warning C4244: '=' : conversion from 'double ' to 'int ', possible loss of data
from my compiler and I was wondering if you guys could let me know how to fix it?
P.S. if you are bored and would like to give me tips on how to make the code better that would be awesome as well.
Thanks a lot,
Allan Franklin
Code:
/* ========================================================================== */
/* GLOBAL HEADER FILES */
#include <stdio.h> /* standard IO routines */
#include <float.h> /* floating point support */
/* ========================================================================== */
/* NAMED CONSTANTS */
#define EARTH 1.00 /* EARTH's weight ratio */
#define JUPITER 2.65 /* JUPITER's weight ratio */
#define MARS 0.39 /* MARS's weight ratio */
#define MERCURY 0.38 /* MERCURY's weight ratio */
#define NEPTUNE 1.23 /* NEPTUNE's weight ratio */
#define PLUTO 0.05 /* PLUTO's weight ratio */
#define SATURN 1.17 /* SATURN's weight ratio */
#define URANUS 1.05 /* URANUS's weight ratio */
#define VENUS 0.78 /* VENUS's weight ratio */
/* ========================================================================== */
/* MAIN FUNCTION */
int main ()
{
int humanWeight, /* Astronaut's weight */
planetChoice, /* User's planet choice */
earthWeight, /* User's final planet weight on Earth */
jupiterWeight, /* User's final planet weight on Jupiter */
marsWeight, /* User's final planet weight on Mars */
mercuryWeight, /* User's final planet weight on Mercury */
neptuneWeight, /* User's final planet weight on Neptune */
plutoWeight, /* User's final planet weight on Pluto */
saturnWeight, /* User's final planet weight on Saturn */
uranusWeight, /* User's final planet weight on Uranus */
venusWeight; /* User's final planet weight on Venus */
/* print introductory message */
printf ("==================================================\n");
printf ("Welcome to the interplanetary weight conversion program!!\n");
printf ("==================================================\n");
/* enter in the astronaut's weight */
printf ("Enter astronaut's weight in pounds on Earth, as a whole number: ");
scanf ("%d", &humanWeight);
/* enter planet number */
printf ("On which planet would you like to know the equivalent weight?\n");
printf ("Please enter the appropriate number for the planet, chosen from the following menu\n");
printf ("1 -- Earth\n");
printf ("2 -- Jupiter\n");
printf ("3 -- Mars\n");
printf ("4 -- Mercury\n");
printf ("5 -- Neptune\n");
printf ("6 -- Pluto\n");
printf ("7 -- Saturn\n");
printf ("8 -- Uranus\n");
printf ("9 -- Venus\n\n");
printf ("Enter your choice: ");
scanf ("%d", &planetChoice); /* User's planet choice */
/* calculations for planet weight */
earthWeight = humanWeight * EARTH;
jupiterWeight = humanWeight * JUPITER;
marsWeight = humanWeight * MARS;
mercuryWeight = humanWeight * MERCURY;
neptuneWeight = humanWeight * NEPTUNE;
plutoWeight = humanWeight * PLUTO;
saturnWeight = humanWeight * SATURN;
uranusWeight = humanWeight * URANUS;
venusWeight = humanWeight * VENUS;
switch ( planetChoice ) {
case 1:
printf ("The astronaut's weight on the planet Earth is %d\n\n", earthWeight);
if (planetChoice == 1);
break;
case 2:
printf ("The astronaut's weight on the planet Jupiter is %d\n\n", jupiterWeight);
if (planetChoice == 2);
break;
case 3:
printf ("The astronaut's weight on the planet Mars is %d\n\n", marsWeight);
if (planetChoice == 3);
break;
case 4:
printf ("The astronaut's weight on the planet Jupiter is %d\n\n", mercuryWeight);
if (planetChoice == 4);
break;
case 5:
printf ("The astronaut's weight on the planet Jupiter is %d\n\n", neptuneWeight);
if (planetChoice == 5);
break;
case 6:
printf ("The astronaut's weight on the planet Jupiter is %d\n\n", plutoWeight);
if (planetChoice == 6);
break;
case 7:
printf ("The astronaut's weight on the planet Jupiter is %d\n\n", saturnWeight);
if (planetChoice == 7);
break;
case 8:
printf ("The astronaut's weight on the planet Jupiter is %d\n\n", uranusWeight);
if (planetChoice == 8);
break;
case 9:
printf ("The astronaut's weight on the planet Jupiter is %d\n\n", venusWeight);
if (planetChoice == 9);
break;
default:
printf ("You have chosen in error please try again.\n\n");
break;
}
/*
if (planetChoice == 1)
printf ("The astronaut's weight on the planet Earth is %d\n\n", earthWeight);
else if (planetChoice == 2)
printf ("The astronaut's weight on the planet Jupiter is %d\n\n", jupiterWeight);
else if (planetChoice == 3)
printf ("The astronaut's weight on the planet Mars is %d\n\n", marsWeight);
else if (planetChoice == 4)
printf ("The astronaut's weight on the planet Mercury is %d\n\n", mercuryWeight);
else if (planetChoice == 5)
printf ("The astronaut's weight on the planet Neptune is %d\n\n", neptuneWeight);
else if (planetChoice == 6)
printf ("The astronaut's weight on the planet Pluto is %d\n\n", plutoWeight);
else if (planetChoice == 7)
printf ("The astronaut's weight on the planet Saturn is %d\n\n", saturnWeight);
else if (planetChoice == 8)
printf ("The astronaut's weight on the planet Uranus is %d\n\n", uranusWeight);
else if (planetChoice == 9)
printf ("The astronaut's weight on the planet Uranus is %d\n\n", venusWeight);
else if (planetChoice <= 1)
printf ("You have chosen in error please try again.\n\n");
else if (planetChoice >= 9)
printf ("You have chosen in error please try again.\n\n");
*/
printf ("Thanks for using the weight conversion program!\n\n");
/* print a closing message and exit program */
printf ("\n-=- Execution Terminated -=-\n");
printf("==================================================\n\n");
return 0;
}
/* ========================================================================== */
/* E N D O F P R O G R A M */
/* ========================================================================== */