Thread: Help on my C programming (noob)

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    36

    Help on my C programming (noob)

    This is the goal:
    Prompt the user for the inner and outer diameter and thickness of the washer to be entered in cm. Then prompt for the material density in grams per cubic cm (g/cm^3) and the number of washers in the batch. Finally, print out the expected weight in kg. Make sure that 3 digits after the decimal are always displayed for your results.

    When executed, it should say:
    Welcome to the Washer Weight Batch Program.
    Please enter the following washer information.

    Inner diameter in cm: 1.2
    Outer diameter in cm: 2.4
    Thickness in cm: 0.1
    Material density in g/cm^3: 7.87
    Quantity in batch: 1000

    The expected weight of the washer batch is 2.670 kg.
    --------------------------------------------------------------------------------------------------------------

    Alright. So this is what I have so far. Please let me know what I need to change or add on.


    Code:
    /* Directives */
    
    #include <stdio.h>
    #define PI 3.14159
    
    int main(void)
    {
    float inner, diameter, thickness, density; NOT SURE ON THESE FLOAT VARIABLES
    
    printf("Welcome to the Washer Weight Batch Program.\n");
    
    printf("Please enter the following washer information.\n");
    
    printf("Inner diameter in cm: ");
    scanf("%f", &inner); NOT TOO SURE ON THESE EITHER.
    printf("Outer diameter in cm: ");
    scanf("%f", &diameter);
    printf("Thickness in cm: ");
    scanf("%f", &thickness);
    printf("Material density in g/cm^3: ");
    scanf("%f", &density);
    printf("Quantity in batch: ");
    
    printf("The expected weight of the washer batch is: %.3f kg.\n");
    
    
    /* End Program */
    return(0);
    
    }
    It's using the correct equations to make the program calculate the expected weight of the washer batch that is getting me stuck. I'm not 100% sure on computing that.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Well, the math doesn't seem like it's that tough.

    First calculate the area of the washer. This is done by: pi*R^2 - pi*r^2. Where R is the outer diameter and r is the inner diameter. Now multiply that by the thickness to get the area. Finally, multiply by the density to get the weight.
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    36
    UPDATE: I am ALMOST THERE!
    When I input(in bold), I don't get the same answer as 2.670 kg. I get 18.096 kg instead.

    Inner diameter in cm: 1.2
    Outer diameter in cm: 2.4
    Thickness in cm: 0.1
    Material density in g/cm^3: 7.87
    Quantity in batch: 1000

    The expected weight of the washer batch is 2.670 kg.

    Code:
    /* homework 6 */
    
    /* Directives */
    
    #include <stdio.h>
    #define PI 3.14159
    
    int main(void)
    {
    float inner, diameter, thickness, density, weight;
    int quantity;
    printf("Welcome to the Washer Weight Batch Program.\n");
    
    printf("Please enter the following washer information.\n");
    
    printf("Inner diameter in cm: ");
    scanf("%e", &inner);
    printf("Outer diameter in cm: ");
    scanf("%E", &diameter);
    printf("Thickness in cm: ");
    scanf("%f", &thickness);
    weight = PI * pow(diameter,2) - PI * pow(inner,2) * thickness * density;
    printf("Material density in g/cm^3: ");
    scanf("%f", &density);
    printf("Quantity in batch: ");
    scanf("%i", &quantity);
    printf("The expected weight of the washer batch is: %.3f kg.\n", weight);
    
    
    /* End Program */
    return(0);
    
    }

  4. #4
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    pow() is declared in <math.h>, have you included it?
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  5. #5
    Registered User
    Join Date
    Sep 2009
    Posts
    36
    Quote Originally Posted by BEN10 View Post
    pow() is declared in <math.h>, have you included it?
    Yeah, after posting it up, I added the <math.h>

    Still not getting the right output. Hmm.

    I'm thinking my math equation to find the area of the washer is not right...

  6. #6
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    Area is PI * r * r not PI * Diameter * Diameter

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Noob to programming need help with a project
    By Wheelsonbus in forum C Programming
    Replies: 6
    Last Post: 02-25-2009, 03:46 AM
  2. Noob printf question
    By lolguy in forum C Programming
    Replies: 3
    Last Post: 12-14-2008, 08:08 PM
  3. noob needs help!!!!:(
    By tykenfitz in forum C Programming
    Replies: 1
    Last Post: 07-10-2005, 08:49 AM
  4. Just a little request from a noob...
    By Lee134 in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 03-18-2005, 05:45 AM
  5. noob: compiling error... plz help!
    By chosii in forum C Programming
    Replies: 2
    Last Post: 05-10-2002, 05:53 AM