Desperado

Discussion in 'C++' started by Gaylle, Mar 24, 2009.

Thread Status:
Not open for further replies.
  1. Gaylle

    Gaylle New Member

    Joined:
    Mar 24, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    hope everyone's fine today. Could someone please write code on this problem so i can understand how to do problems like these? would be very grateful.


    Geometry Calculator:
    * Use nested if-else statements for all decision making in the program.
    * Declare PI as a double constant with value 3.14159
    * Use a while loop to repeat until the user types a 4 as shown below. If the operation code is not 1 through 4, then print an error message and go to the next data item.
    * If a negative data value is entered by the user (or read from file), make it positive and use it.
    * Use double for all your data variables and print all values with 4 decimal places.
    * When the operation is 4, print "Thank you for using my calculator" and end the program.
    * In the data given, the first figure is the operation value. An operation value of 1 refers a circle and the next value is the radius. An operation value of 2 refers to a rectangle and the next 2 values are the length and width. An operation value of 3 refers to a triangle and the values after it are the base and height of the triangle. Operation values of 5 and 7 should show error messages
    *Any value less than 0 should be multiplied by -1 before being used.


    int operation;
    // display the menu
    cin >> operation;
    while (operation != 4)
    {
    // put your calculations here
    // display the menu
    cin >> operation;
    }


    OPERATIONS & DATA VALUES

    1 4.58
    2 6.34 5.8
    3 7 -13
    5
    2 -6 19.4443
    3 81.8 0.543
    1 -8976
    7
    2 12.58 3
    4

    After you have the program running on the screen, change the I/O to file I/O. Your output should be as shown in the sample below, with a blank line between each output:


    The area of a circle with radius 4.5800 is 14.3885
    Error: 5 is not a valid operation
    The area of a triangle with base 7.0000 and height 13.0000 is 45.5000
    Thank you for using my calculator
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    We won't do your assignment for you but we will help you do it.
    How far have you got with it and where are you stuck?
    Are you getting any errors, or wrong behaviour in the code you've got so far?
    Describe clearly what your current problem is.

    It looks like you've been given a starting point. Is your code correctly doing "Use a while loop to repeat until the user types a 4 as shown below. If the operation code is not 1 through 4, then print an error message and go to the next data item." ?

    Hint: don't try to write all the code at once. I've been programming since 1981 and I don't do that (not that I hold myself up as any kind of expert). Get one part working, then work on the next bit and get that working, and repeat until the assignment is completed.


    Hmm, looks like you have actually made some progress:
    http://www.go4expert.com/showthread.php?t=16653

    Rather than having us waste our time trying to solve problems you've already got past, if you post a thread with a problem, then solve it, would you please follow up that post with one that just says something like "never mind, sorted it"?
     
  3. Gaylle

    Gaylle New Member

    Joined:
    Mar 24, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    i dont understand why everyone seems to think i had sorted out the problem. i hadnt. dont kno where the misunderstanding is coming from. thanks for the help tho.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Thread closed. Keep everything into one thread.
     
Thread Status:
Not open for further replies.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice