Thread: Writing a Code

  1. #1
    Registered User
    Join Date
    Feb 2020
    Posts
    3

    Writing a Code

    I am very new to programming and need to write a code to use input. An example input is 5.1, 8.3, 12.2, 8.4 and the expected output is:

    Enter x1 and x2.
    You entered x1 as 5.10 and x2 as 8.30.
    Enter y1 and y2.
    You entered y1 as 12.20 and y2 as 8.40.

    From the lower-left point clockwise,
    the points of the trapezoid are:
    (5.10, 0.00)
    (5.10, 12.20)
    (8.30, 8.40)
    (8.30, 0.00)
    The area of the trapezoid is 32.96 units.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    3,874
    Quote Originally Posted by jdouglass View Post
    I am very new to programming and need to write a code to use input. An example input is 5.1, 8.3, 12.2, 8.4 and the expected output is:

    Enter x1 and x2.
    You entered x1 as 5.10 and x2 as 8.30.
    Enter y1 and y2.
    You entered y1 as 12.20 and y2 as 8.40.

    From the lower-left point clockwise,
    the points of the trapezoid are:
    (5.10, 0.00)
    (5.10, 12.20)
    (8.30, 8.40)
    (8.30, 0.00)
    The area of the trapezoid is 32.96 units.
    Introduction to C - Cprogramming.com
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Feb 2019
    Posts
    697
    Are you sure you'll end up with a trapeze for every possible values of y? What if x1=5.10, x2=8.3, y1=12.2 and y2=-10?
    Last edited by flp1969; 02-05-2020 at 09:36 AM.

  4. #4
    Registered User
    Join Date
    Dec 2017
    Posts
    952
    Quote Originally Posted by flp1969 View Post
    Are you sure you'll end up with a trapeze for every possible values of y?
    Only very special values of y (magical values indeed) will create a trapeze.
    If you want the truth to stand clear before you, never be for or against. - Sent-ts'an

  5. #5
    Registered User
    Join Date
    Feb 2020
    Posts
    3
    Quote Originally Posted by flp1969 View Post
    Are you sure you'll end up with a trapeze for every possible values of y? What if x1=5.10, x2=8.3, y1=12.2 and y2=-10?
    This is the output that I was given for the input, so really I'm not sure.

  6. #6
    Registered User
    Join Date
    Feb 2019
    Posts
    697
    Quote Originally Posted by jdouglass View Post
    This is the output that I was given for the input, so really I'm not sure.
    Really? You do know how to draw with pencil and paper, don't ya?

  7. #7
    Registered User
    Join Date
    Feb 2020
    Posts
    3
    Quote Originally Posted by flp1969 View Post
    Really? You do know how to draw with pencil and paper, don't ya?
    I am in college taking a 101 course in computer programming with 0 prior background in computer science. This is the second class and we were told to compute it, so just asking for a little help....

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    3,874
    Quote Originally Posted by stahta01 View Post
    The above is a weblink click on it and read the information!

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,857
    Well, the thing is that code comes towards the end of the (initial) problem solving process. Start by understanding the problem, and in this case one approach is to try different input values and draw the result out on paper. From there you have a better chance of understanding how to arrive at the results (i.e., how to determine the points and compute the area), and hence you can write the code to produce the results from the input.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help writing this code, please.
    By antonio.gor in forum C Programming
    Replies: 0
    Last Post: 10-12-2015, 11:18 PM
  2. Changing writing code to reading code
    By binks in forum C Programming
    Replies: 8
    Last Post: 06-12-2012, 09:41 AM
  3. writing good code is like writing an artistic expression
    By renzokuken01 in forum C Programming
    Replies: 5
    Last Post: 02-03-2011, 08:48 PM
  4. Need some help on writing code
    By A slow C++ user in forum C++ Programming
    Replies: 7
    Last Post: 02-20-2003, 09:32 PM

Tags for this Thread