CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    Join Date
    May 2013
    Posts
    12

    Re: PLEASE with this code!!!!!

    I know that there is 12inches for every foot and that for every inch there is 2.54 centimeters. and I know that for every foot there is .3048 meters.....

  2. #17
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: PLEASE with this code!!!!!

    Quote Originally Posted by bobr View Post
    I know that there is 12inches for every foot and that for every inch there is 2.54 centimeters. and I know that for every foot there is .3048 meters.....
    Okay, so what would be the steps involved in converting say 7'3" to meters and centimeters? Just in English, not code.

  3. #18
    Join Date
    May 2013
    Posts
    12

    Re: PLEASE with this code!!!!!

    I know that their is 12inches per foot....for every inch their is 2.54 centimeters and for every foot there is .3048 meters...

  4. #19
    Join Date
    May 2013
    Posts
    12

    Re: PLEASE with this code!!!!!

    I would multiple 7 feet by .3048 meters and multiply 3inches by 2.54cm

  5. #20
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: PLEASE with this code!!!!!

    Quote Originally Posted by bobr View Post
    I would multiple 7 feet by .3048 meters and multiply 3inches by 2.54cm
    No. Multiplying the whole number feet by a decimal number is why you're getting compiler warnings in the first place. Remember for this exercise you need to convert everything to inches first.

    Again the steps are convert feet and inches to inches.
    Convert inches to centimeters.
    Convert centimeters to meters and centimeters.

  6. #21
    Join Date
    May 2013
    Posts
    12

    Re: PLEASE with this code!!!!!

    okay take my input number of feet and multiply by 12inches.....then take the total number of inches and multiply by 2.54 cm.....then take my total number of cm and multiply by .01 meters

  7. #22
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: PLEASE with this code!!!!!

    Quote Originally Posted by bobr View Post
    okay take my input number of feet and multiply by 12inches.....then take the total number of inches and multiply by 2.54 cm.....then take my total number of cm and multiply by .01 meters
    Not really. I'm not trying to be a jerk, but you need to understand the process yourself in order to explain it to the computer. I'm sure you know how to do it, but you need to figure out all the steps, and you're missing a few.

    Multiplying the feet by 12 gives you 84.
    multiply 84 by 2.54 gives you 213.36.
    Multiplying that gives you 2.1336, which is not only incorrect, but I don't believe it satisfies the requirement of using an int for meters and a double for centimeters. Further, if you do follow the requirements and keep meters an int, your result will be 2, which is even further for the correct result.

    I'll help with the first two steps.

    Multiply the number of feet by 12.
    Add that number to the number of inches.

  8. #23
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: PLEASE with this code!!!!!

    When programming, the first step is to design the program specifiying the input, output, algorithm, steps required etc. This includes the steps that GCDEF has been asking you re how to do a conversion in English. Once, and only once, the design has been done and checked by walkthrough etc is the design coded. Once coded, it is tested and debugged. If the program doesn't perform as expected then its either a problem coding the design or a problem with the design itself. If the program design is not right, then the coded program will not work properly. As GCDEF has said, you must understand the process and know all the steps before you start coding.

    I suggest you take a step back from the code, produce a proper program design that includes all the steps etc. Then when you are happy with the design then code your program from the design.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured