Volume calculator problems

This is a discussion on Volume calculator problems within the C Programming forums, part of the General Programming Boards category; SOLVED Here is my code when i try to run the program it ask me to type in my value ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    25

    Volume calculator problems

    SOLVED
    Here is my code when i try to run the program it ask me to type in my value for width. I enter a value and press enter. The program then goes to the next line and waits another value entry before proceeding to ask me for the height of the object. I don't know why it wont ask only a single time for the width.

    Code:
    // This program is intended to calculate the volume of a box
    
    #include <stdio.h>
    
    int main()
    
    {
    	float height;
    	float width;
    	float length;
    	float volume;
    	char finish;
    
    	printf( "please enter the width of the box"); //this is the width
    		scanf( "%f\n" , &width);
    	
    	printf("please enter the height of the box"); //this is the height of the box
    		scanf( "%f\n" , &height);
    
    	printf( "please enter the length of the box"); //this is the length
    		scanf( "%f\n" , &length);
    
    	volume = height*width*length; // this equation finds the volume
    
    	printf( "The volume of the box is %f cubic units\n", volume ); //final statment
    		getchar();
    
    	printf( "enter f to exit the program"); //exiting the program
    		scanf( "%c" , &finish );
    
    	return 0;
    }
    Last edited by jackalope; 09-26-2010 at 12:16 AM.

  2. #2
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    Heya. Try taking the \n out of the scanf so
    Code:
     
    scanf("%f\n", &width);
    changed to
    Code:
    scanf("%f, &width);
    then change the printf to
    Code:
    printf("please enter the width of the box\n");
    Do that for all three width, height, and length, and you should be golden.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    scanf("%f", &width);

  4. #4
    Registered User
    Join Date
    Sep 2010
    Posts
    25
    you my friend are a genius. I didn't realize that they should be put there instead of in the other box. cheers

  5. #5
    Registered User
    Join Date
    Sep 2010
    Posts
    25
    this can be closed btw

  6. #6
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    they don't close threads in the chance that someone else experiences the same problem. That way others can learn from your question... but if you are concerned with others "wasting their time reading it" You can always edit your first post and just add "SOLVED" to the very first line so when people mouseover the thread they see Solved first and know its already been fixed, but please don't delete the content of your post just add the words SOLVED. Welcome to the board by the way ;o).

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Just my luck - finally get recognized for the genius I believe I am, and immediately my fan wants to close the thread!!

    It ain't fair!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 44
    Last Post: 03-19-2010, 04:06 PM
  2. Detect the Audio And Microphone Level In Windows
    By Kelderic in forum C Programming
    Replies: 6
    Last Post: 11-17-2009, 11:21 PM
  3. Volume of a Cone Equation always equals 0
    By Devolution in forum C Programming
    Replies: 11
    Last Post: 01-28-2009, 02:13 AM
  4. Help! Right Math, Wrong Output
    By verd in forum C Programming
    Replies: 12
    Last Post: 03-15-2005, 06:49 PM
  5. What am I doing wrong? Help please...
    By SprinterSteve in forum C Programming
    Replies: 9
    Last Post: 04-17-2003, 09:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21