Thread: Double to Int conversion warning

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    8

    Double to Int conversion warning

    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 */
    /* ========================================================================== */

  2. #2
    Registered User
    Join Date
    Sep 2005
    Posts
    8
    oh I also need to make the program so that if you enter the astronaut's weight at the beginning and it is less than 0, then it will skip down to the end and prompt the user to start over.

    Thanks

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    The warning comes from your calculations:
    Code:
    earthWeight		=	humanWeight * EARTH;
    The warning is basically telling you that humanWeight * EARTH is giving you a double value, but you are then assigning it to an int. This means you lose everything past the decimal point. If this is what you wanted, then you can get rid of the warnings by casting your return values like so:
    Code:
    earthWeight		=	(int)humanWeight * EARTH;

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    8
    Thank you for the quick reply, I made the changes that you suggested and my compiler, (microsoft visual C++), still states that there is a warning for conversion from double to int.
    please let me know if there is anything else I need to do.

    Thank you,
    Allan

  5. #5
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Did you cast every line ? Because what bithub meant was :

    Code:
    /*  Your code */
    
    /* 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;
    That's not right, what he wanted you to do is :

    Code:
    /*  Right Code  */
    /* calculations for planet weight */
    	
    	earthWeight		=	(int)(humanWeight * EARTH);
    	jupiterWeight	=	(int)(humanWeight * JUPITER);
    	marsWeight		=	(int)(humanWeight * MARS); 
    	mercuryWeight	=	(int)(humanWeight * MERCURY); 
    	neptuneWeight	=	(int)(humanWeight * NEPTUNE);
    	plutoWeight		=	(int)(humanWeight * PLUTO); 
    	saturnWeight	=	(int)(humanWeight * SATURN);
    	uranusWeight	=	(int)(humanWeight * URANUS); 
    	venusWeight		=	(int)(humanWeight * VENUS);
    Either you do that, or you turn all your *Weight variables to doubles. Try that. If there's more problems, can you please specify on which line the warning is raised ?
    Last edited by Happy_Reaper; 09-19-2005 at 10:19 AM.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    8
    Sorry for the constant questions, but I also need help in writing a code that makes the user start over if they put a number that is less than zero in for the astronaut's weight.

    Thanks,
    Allan

  7. #7
    Registered User
    Join Date
    Sep 2005
    Posts
    8
    thanks a lot guys, my problem is solved with the warnings, now I need to figure out how to start the user over they put in an invalid number for the astronaut's weight.

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    do
        prompt user for something
        get value for something
    while value for something less than minimum valid value
    Have fun.


    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    Registered User
    Join Date
    Sep 2005
    Posts
    8
    sorry for being an idiot, but i have no idea how to do what you just said.

    thanks,
    Allan

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Which part? Haven't you covered loops in your class or book? I doubt they'd ask you to do something you haven't covered. Go back and read up on loops. You must have covered how to prompt for something, because you've got printf statements in your program already, unless you just copied that from someone. You must know how to get some input from the user, because you've got scanf statements in your program. Unless you just copied that too.

    Use your head for a couple of seconds. It's not hard. The only way I could have made it any easier would be to have done the whole thing for you.


    Quzah.
    Hope is the first step on the road to disappointment.

  11. #11
    Registered User
    Join Date
    Sep 2005
    Posts
    8
    here is the code that i have come up with. the only problem I am having is that when a user puts in a negative value for "humanWeight," i want the program to start over. Right now i have a switch statement but for some reason it is just starting the program over even if the value is valid.

    I am doing my best to figure it out, but this is all I can come up with for now. I have only 2 weeks of experience in programming and prior to this I never even thought about the subject.



    Code:
    /* ========================================================================== */
    /* GLOBAL HEADER FILES */
    
    #include <stdio.h>					/* standard IO routines */
    #include <float.h>					/* floating point support */	
    #include <math.h>					/* math 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 
    			
    			planetChoice,			/* User's planet choice */
    			humanWeight;			/* Astronaut's weight */
    	
    	double	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);
    
    	switch ( humanWeight ) {
    case 1:
    	printf	("On which planet would you like to know the equivalent weight?\n");
    	  if (humanWeight >= 0);
    	break;
    default: 
    	printf	("Astronaut's weight is an invalid value, please try again.\n");
    	return 0;
    	 
    }
    
    
    	/* enter planet number */
    	
    
    	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		=	(double)humanWeight * EARTH;
    	jupiterWeight	=	(double)humanWeight * JUPITER;
    	marsWeight		=	(double)humanWeight * MARS; 
    	mercuryWeight	=	(double)humanWeight * MERCURY; 
    	neptuneWeight	=	(double)humanWeight * NEPTUNE;
    	plutoWeight		=	(double)humanWeight * PLUTO; 
    	saturnWeight	=	(double)humanWeight * SATURN;
    	uranusWeight	=	(double)humanWeight * URANUS; 
    	venusWeight		=	(double)humanWeight * VENUS;
    
    	switch ( planetChoice ) {
    case 1:
      printf	("The astronaut's weight on the planet Earth is %1.0f\n\n", floor (earthWeight));
    	  if (planetChoice == 1);
      break;
    case 2:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (jupiterWeight));
    	  if (planetChoice == 2);
      break;
    case 3:
      printf	("The astronaut's weight on the planet Mars is %1.0f\n\n", floor (marsWeight));
    	  if (planetChoice == 3);
      break;
    case 4:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (mercuryWeight));
    	  if (planetChoice == 4);
      break;
    case 5:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (neptuneWeight));
    	  if (planetChoice == 5);
      break;
    case 6:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (plutoWeight));
    	  if (planetChoice == 6);
      break;
    case 7:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (saturnWeight));
    	  if (planetChoice == 7);
      break;
    case 8:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (uranusWeight));
    	  if (planetChoice == 8);
      break;
    case 9:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (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 */
    /* ========================================================================== */

  12. #12
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Code:
    if (humanWeight >= 0);
    if() statements shouldn't have a semi-colon after them. It's a common mistake. Its presence tells the compiler that if the if() is true, do nothing. So basically your if() statement does nothing at all in any situation.

    EDIT: The basic rule is that any kind of branching statement should not have a semi-colon. switch(), if(), while(), for()...none of them should have a semi-colon after them.
    Last edited by itsme86; 09-19-2005 at 12:07 PM.
    If you understand what you're doing, you're not learning anything.

  13. #13
    Registered User
    Join Date
    Sep 2005
    Posts
    8
    thanks a lot for your help everyone.

    I have the program working and error free.

    here is my final code:

    Code:
    /* ========================================================================== */
    /* GLOBAL HEADER FILES */
    
    #include <stdio.h>					/* standard IO routines */
    #include <float.h>					/* floating point support */	
    #include <math.h>					/* math 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 
    			
    			planetChoice,			/* User's planet choice */
    			humanWeight;			/* Astronaut's weight */
    	
    	double	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);
    
    	if ( humanWeight >= 0 ) {
    
    	printf	("On which planet would you like to know the equivalent weight?\n\n");
    }
    	else {
    
    		printf ("User has entered Astronaut's weight in error, please try again.\n");
    	
    return 1;
    	 
    }
    
    
    	/* enter planet number */
    	
    
    	printf	("Please enter the appropriate number for the planet that you have chosen.\n\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		=	(double)humanWeight * EARTH;
    	jupiterWeight	=	(double)humanWeight * JUPITER;
    	marsWeight		=	(double)humanWeight * MARS; 
    	mercuryWeight	=	(double)humanWeight * MERCURY; 
    	neptuneWeight	=	(double)humanWeight * NEPTUNE;
    	plutoWeight		=	(double)humanWeight * PLUTO; 
    	saturnWeight	=	(double)humanWeight * SATURN;
    	uranusWeight	=	(double)humanWeight * URANUS; 
    	venusWeight		=	(double)humanWeight * VENUS;
    
    	switch ( planetChoice ) {
    case 1:
      printf	("The astronaut's weight on the planet Earth is %1.0f\n\n", floor (earthWeight));
    	  if (planetChoice == 1);
      break;
    case 2:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (jupiterWeight));
    	  if (planetChoice == 2);
      break;
    case 3:
      printf	("The astronaut's weight on the planet Mars is %1.0f\n\n", floor (marsWeight));
    	  if (planetChoice == 3);
      break;
    case 4:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (mercuryWeight));
    	  if (planetChoice == 4);
      break;
    case 5:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (neptuneWeight));
    	  if (planetChoice == 5);
      break;
    case 6:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (plutoWeight));
    	  if (planetChoice == 6);
      break;
    case 7:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (saturnWeight));
    	  if (planetChoice == 7);
      break;
    case 8:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (uranusWeight));
    	  if (planetChoice == 8);
      break;
    case 9:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (venusWeight));
    	  if (planetChoice == 9);
      break;
    default:
      printf	("You have chosen in error please try again.\n\n");
      return 1;
    }
    
    
    /*
    	
    	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 */
    /* ========================================================================== */

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by wiznant
    thanks a lot for your help everyone.

    I have the program working and error free.

    here is my final code:

    Code:
    	switch ( planetChoice ) {
    case 1:
      printf	("The astronaut's weight on the planet Earth is %1.0f\n\n", floor (earthWeight));
    	  if (planetChoice == 1);
      break;
    case 2:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (jupiterWeight));
    	  if (planetChoice == 2);
      break;
    case 3:
      printf	("The astronaut's weight on the planet Mars is %1.0f\n\n", floor (marsWeight));
    	  if (planetChoice == 3);
      break;
    case 4:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (mercuryWeight));
    	  if (planetChoice == 4);
      break;
    case 5:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (neptuneWeight));
    	  if (planetChoice == 5);
      break;
    case 6:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (plutoWeight));
    	  if (planetChoice == 6);
      break;
    case 7:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (saturnWeight));
    	  if (planetChoice == 7);
      break;
    case 8:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (uranusWeight));
    	  if (planetChoice == 8);
      break;
    case 9:
      printf	("The astronaut's weight on the planet Jupiter is %1.0f\n\n", floor (venusWeight));
    	  if (planetChoice == 9);
      break;
    default:
      printf	("You have chosen in error please try again.\n\n");
      return 1;
    }
    Are you even reading what people write here? My sources say no.


    Quzah.
    Hope is the first step on the road to disappointment.

  15. #15
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Don't forget
    Code:
    if (planetChoice == 9);


    The basic rule is that any kind of branching statement should not have a semi-colon. switch(), if(), while(), for()...none of them should have a semi-colon after them.
    Well, they can, but not at that level. do-whiles have a semicolon, though, always.

    The exception proves the rule.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ to C Conversion
    By dicon in forum C Programming
    Replies: 7
    Last Post: 06-11-2007, 08:38 PM
  2. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  3. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM
  4. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM
  5. A Simple (?) Problem
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 10-12-2001, 04:28 AM