Thread: help on how to get started.

  1. #1
    Registered User
    Join Date
    Sep 2014
    Posts
    4

    Lightbulb help on how to get started.

    Purpose: Do some computations.

    Description:

    Create a C program that reads in three integer values
    representing the height, width and length of a rectangular
    prism/box. Compute the following results using those three
    values:

    Areas:
    - Surface area of the top
    - Surface area of the front face
    - Surface area of an end
    - Surface area of the entire prism

    Perimeters:
    - of the bottom
    - of the front face
    - of an end

    Volume:
    - of the prism

    Chord:
    - diagonal distance across the prism. That is: the
    single chord that crosses the prism from
    left-to-right, top-to-bottom, and front-to-back.

    Notes:
    -----
    - Read the three integer input values in the order they were
    first mentioned above: height, width, length.
    - Print the results in the order listed above.

    - Do as much integer math as possible. (Since the inputs are
    integers, almost all the results will also be integers.)

    - Nicely format and label your output.

    - Gradually develop your program in steps:
    - Read in your inputs and print them out to confirm
    you are reading them in correctly
    - Compute just one of the computed values
    - Add additional computations one at a time
    - Ask about any of the math you are not sure of

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Purpose: Do some computations.

    Description:

    Create a C program that reads in three integer values
    representing the height, width and length of a rectangular
    prism/box. Compute the following results using those three
    values:

    Areas:
    - Surface area of the top
    - Surface area of the front face
    - Surface area of an end
    - Surface area of the entire prism

    Perimeters:
    - of the bottom
    - of the front face
    - of an end

    Volume:
    - of the prism

    Chord:
    - diagonal distance across the prism. That is: the
    single chord that crosses the prism from
    left-to-right, top-to-bottom, and front-to-back.

    Notes:
    -----
    - Read the three integer input values in the order they were
    first mentioned above: height, width, length.
    - Print the results in the order listed above.

    - Do as much integer math as possible. (Since the inputs are
    integers, almost all the results will also be integers.)

    - Nicely format and label your output.

    - Gradually develop your program in steps:
    - Read in your inputs and print them out to confirm
    you are reading them in correctly
    - Compute just one of the computed values
    - Add additional computations one at a time
    - Ask about any of the math you are not sure of
    A good place for you to start is to read integers - Google scanf()

    Other tips
    A development process

    And be aware of this:
    Announcements - General Programming Boards
    Fact - Beethoven wrote his first symphony in C

  3. #3
    Registered User
    Join Date
    Sep 2014
    Posts
    4
    Code:
      #include <stdio.h>
     #include <math.h>
     #include <iostream>
     int main()
     {
     int h; 
     int w;
     int l;
     int value;
     int vol;
     int SaTop;
     
     /* Read in inputs of Height, Width, Length and print them out. */
     printf("The height of the regtangular prism is.\n");
     scanf("%d", & h);
     printf("The width of the regtangular prism is.\n");
     scanf("%d", & w);
     
     printf("The lenght of the regtangular prism is.\n");
     scanf("%d", & l);
     /* Volume */
     /* Calculating the Volume of the rectangular prism/box. */
     vol= h*w*l;
     
     scanf("%d%d%d", & h, & w, & l);
     printf("Volume is: %d\n", vol);
     /* Areas */
     /* Calculating the Surface area of the top */
     SaTop= w*l
     
     scanf("%d%d%d",& h, & w, & l);
     printf("Surface Area of the top is: %d\n", SaTop);
     
     
     
     system("PAUSE"); //dos specific 
     return h*w*l;
     return w*l
     
     } 
    


    any feedback this is how it looks currently.





  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Quote Originally Posted by mahad View Post
    any feedback this is how it looks currently.
    1. You should post the code in plain text only and with reasonable indentation.
    2. You need a semicolon after each statement.
    3. Don't include C++ headers like iostream.h in a C program
    4. To call system you need to include <stdlib.h>
    5. Some lines didn't make sense so I commented them out - e.g. you are trying to return large integers from main which is probably not what you want. Normally you print the result using printf (which you did already) and you return 0 from main to mean the program exited successfully.

    There are still some problems in your program. For example, you are reading h, w and l again without any prompt (see line 26) for a second time. Also I think you should output the result of computation before moving on for more input (would make more sense to the user). Or even better I would say try at first to make a program to just compute the volume, then make another program to just compute the surface area. Then see how you could do them both in one program?


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        int h;
        int w;
        int l;
    //    int value;
        int vol;
        int SaTop;
    
        /* Read in inputs of Height, Width, Length and print them out. */
        printf("The height of the regtangular prism is.\n");
        scanf("%d", &h);
        printf("The width of the regtangular prism is.\n");
        scanf("%d", &w);
    
        printf("The lenght of the regtangular prism is.\n");
        scanf("%d", &l);
    
        /* Volume */
        /* Calculating the Volume of the rectangular prism/box. */
        vol= h*w*l;
    
        scanf("%d%d%d", &h, &w, &l);
        printf("Volume is: %d\n", vol);
    
        /* Areas */
        /* Calculating the Surface area of the top */
        SaTop= w*l;
    
        scanf("%d%d%d", &h, &w, &l);
        printf("Surface Area of the top is: %d\n", SaTop);
    
        system("PAUSE"); //dos specific
        return 0;
    //    return h*w*l;
    //    return w*l;
    }

  5. #5
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    That was a fairly good first try

    C99tutorial's response covered all you need to keep going.

    I might add a few points (following on from C99tutorial's code) -
    Line 19: You have spelt "length" wrong
    Line 26: This looks a bit out of place. If you want to replace the values w/l/h, you'll want to prompt the user.

    Don't forget the requirements in the last paragraph of your first post, as you don't seem to be following it
    Fact - Beethoven wrote his first symphony in C

  6. #6
    Registered User
    Join Date
    Sep 2014
    Posts
    4
    Code:
    Purpose: Write some simple functions.
     
     Description:
     
     Modify your program for assignment #3 to have 3 functions in addition to main( ). The additional functions should:
       1) Print an "overall" set of instructions to describe what
          the program is about to do for the user and what it will
          require for inputs.
       2) Compute the area of a rectangle. {This will be used to
          compute each of the required surface areas.}
       3) Compute the perimeter of a rectangle. {This will be used
          to compute each of the required perimeters.}
     
     Notes:
     -----
     - Read and meet all requirements of assignment #3.
     
     - Gradually develop your program in steps:
         - Add one function at a time to your Assignment #3
           solution and check that it is working properly. Then
           add an additional function, until all functions are
           present.
    I got the other programming going, but im not sure how to add on it with simple functions.
    help please. Am i suppose to have different headers on top for some functions?

  7. #7
    Registered User
    Join Date
    Sep 2014
    Posts
    4
    Code:
    #include <stdio.h>
    #include <math.h>
    
    
    int main()
    {
        int h; 
        int w;
        int l;
        int value;
        int vol;
        int SaTop;
        int SaFront;
        int SaEnd;
        int SaPrism;
        int PerBottom;
        int PerFront;
        int PerEnd;
        float diagonal_ofprism;
        float Chord_ofprism;
       
       
       
       
     /* Read in inputs of Height, Width, Length and print them out. */
    
     printf("The height of the regtangular prism is.\n");
     scanf("%d", & h);
    
     printf("The width of the regtangular prism is.\n");
     scanf("%d", & w);
     
     printf("The lenght of the regtangular prism is.\n");
     scanf("%d", & l);
     /* Volume */
     /* Calculating the Volume of the rectangular prism/box. */
     vol= (h*w*l);
     
     /* Areas of prism */
     /* Calculating the surface area of the top */
     SaTop= l*w;
     
     /* Calculating the surface area of the front face*/
     SaFront= h*l;
     
     /* Calculating the surface area of an end*/
     SaEnd= h*w;
     
     /* Calculating the surface area of the whole prism*/
     SaPrism= (w*l*2)+(h*w*2)+(h*l*2);
     /* Perimeters of the prism*/
     /* Calculating the perimeters of the bottom*/
     PerBottom= (2*w)+(2*l);
     
     /* Calculating the perimeters of the front face*/
     PerFront= (2*h)+(2*l);
     
     /* Calculating the perimeters of an end*/
     PerEnd= (2*h)+(2*w);
     
     /* Calculating the diagonal distance across the prism*/
      diagonal_ofprism= (w*w)+(l*l);
      
      /* Calculating the single chord that crosses the prism*/
      Chord_ofprism= sqrt(diagonal_ofprism+(h*h));
      
     
     
     
     
     /* Output*/
     
     /* Printout Volume of prism*/
     vol=(h*w*l);
     printf("Volume is: %d in cubed\n", vol);
     /* Printout the surface area of the top*/
     SaTop= l*w;
     printf("Surface area of the top:%d in sqrt\n", SaTop);
    /* Printout the surface area of the front face*/
    SaFront= h*l;
    printf("Surface area of the front face: %d in sqrt\n", SaFront);
    /* Printout surface area of an end*/
    SaEnd= h*w;
    printf("Surface area of an end: %d in sqrt\n", SaEnd);
    /* Printout the surface area of the entire prism*/
    SaPrism= (w*l*2)+(h*w*2)+(h*l*2);
    printf("Surface area of the whole prism: %d in sqrt\n", SaPrism);
    /* Printout the perimeters of the bottom*/
    PerBottom= (2*w)+(2*l);
    printf("Perimeters of the bottom of the prism: %d in\n", PerBottom);
    /* Printout the perimeters of the front face*/
    PerFront= (2*h)+(2*l);
    printf("Perimeters of the front face of the prism: %d in\n", PerFront);
    /* Printout the perimeters of an end*/
    PerEnd= (2*h)+(2*w);
    printf("Perimeters of and end of the prism: %d in\nn", PerEnd);
    /* Printout the diagonal distance across the prism*/
     diagonal_ofprism= (w*w)+(l*l);
     printf("Diagonal distance across the prism: %f in\n", diagonal_ofprism );
     /*Printout the single chord that crosses the prism*/
     Chord_ofprism= sqrt(diagonal_ofprism+(h*h));
     printf("Single chord that crosses the prism: %f in\n", Chord_ofprism );
    
    
    
    
     
    
     system("pause");
     
      
      
        return 0;
        
        
    }
    This is what I have for my third assignment able to run as well.

  8. #8
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Why are you doing each calculation twice? The first half of the program does all the calculations, and the second half does them all again before they are printed out.

    If this is your attempt at the assignment from two posts above, you're missing the functions that are required.

    Note that there is literally nothing we can do to help you with that as it stands. The assignment requires the most basic implementation of functions, and you have made no attempt. We could only (1) teach you functions from scratch, or (2) just do them for you. Neither of these things will happen, since learning is your responsibility (we're here to help you along the way) and we don't do hand-outs.

    If you have absolutely no idea how to do your own functions, you need to open your book (or find a suitable tutorial - there are some here on this very site) and starting learning about it.

    If you do have an idea, make a decent attempt and, if you get stuck, show your work and ask specific questions.

    Am i suppose to have different headers on top for some functions?
    You don't need different headers for your own custom functions.

    (Exception 1: If you're using multiple source files, which you're not.)
    (Exception 2: If the function calls functions from other libraries, but you've already dealt with this in "main()" so it's no different.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 07-30-2013, 01:28 AM
  2. Getting Started
    By MadnessRed in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 08-23-2008, 04:52 AM
  3. When you started
    By xInfested in forum C++ Programming
    Replies: 3
    Last Post: 02-18-2008, 03:26 AM
  4. Getting started
    By Rainer in forum Game Programming
    Replies: 16
    Last Post: 09-23-2003, 04:23 PM
  5. just started
    By vivek_kumbhar in forum C Programming
    Replies: 3
    Last Post: 07-07-2003, 04:25 PM