Thread: Need Help Fast!!!!

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    11

    Need Help Fast!!!!

    This is my program so far:

    /* This Program has been created to figure out how much it cost to build a Fish Tank. This will be done by inputing the Width, Length, and Height in which the computer in return will calculate the price */

    #include <stdio.h>

    int main(void)
    {
    int interger; int L,W,H;
    printf("What is the length of your goldfish tank in inches?\n");
    scanf( "%d", &L );
    printf("What is the width of your goldfish tank in inches?\n");
    scanf( "%d", &W );
    printf("What is the height of your goldfish tank in inches?\n");
    scanf( "%d", &H );
    printf("Your goldfish tank costs ????? to
    build.\n");
    return 0;
    }



    How do i get this formula (2*(H*W)+2*(L*H)+(L*W))*(.02)) inserted in the right format where those question marks are? So when the program runs the price will come up in $XX.XX format??

  2. #2
    Simple,

    Just create a floating-type variable:

    Code:
    float cost = (2.0f*(H*W)+2.0f*(L*H)+(L*W))*(.02f);
    Then print it:

    Code:
    printf("Your goldfish tank costs $%1.2f to build.\n", cost);

    Hope this helps,
    - Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    11
    Where do i put the floating-type variable? (sorry im a freshman in college and im very new to Programming)

  4. #4
    No problem.

    Here is an overview of the whole code:

    Code:
    int main(void) {
    	int L,W,H;
    	float cost;
    
    	printf("What is the length of your goldfish tank in inches?\n");
    	scanf( "%d", &L );
    	printf("What is the width of your goldfish tank in inches?\n");
    	scanf( "%d", &W );
    	printf("What is the height of your goldfish tank in inches?\n");
    	scanf( "%d", &H );
    
    	cost = (2.0f*(H*W)+2.0f*(L*H)+(L*W))*(.02f);
    
    	printf("Your goldfish tank costs $%1.2f to build.\n", cost);
    
    	return 0;
    }
    For future reference, here is some information about printf().


    Hope this makes sense,
    - Stack Overflow
    Last edited by Stack Overflow; 09-14-2004 at 05:20 PM.
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    11
    Thanks alot man it worked you are a life saver!!!!!

  6. #6
    Glad to be of help
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 02-27-2009, 04:43 PM
  2. Saving a part of screen into a file fast!
    By Zap in forum C++ Programming
    Replies: 4
    Last Post: 06-28-2003, 10:56 AM
  3. Super fast bilinear interpolation
    By VirtualAce in forum Game Programming
    Replies: 2
    Last Post: 06-18-2002, 09:35 PM
  4. Fast clrscr function
    By GaPe in forum C Programming
    Replies: 24
    Last Post: 06-13-2002, 12:54 AM
  5. moving a bitmap, fast and smooth
    By werdy666 in forum Game Programming
    Replies: 1
    Last Post: 05-31-2002, 06:49 PM