Thread: Unit converter calculator help

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    17

    Unit converter calculator help

    Greetings all, I am a senior Industrial Engineer major at Wayne State University in Detroit, MI who took a 1000 level (100 at most schools) computer class as an elective, and quickly discovered I was in over my head. Here's my problem, and what my instructor asks of me:

    "I would like you to develop a unit conversion calculator that allows the
    user to convert english units into metric units and vice-versa.

    The user should prompted for the conversion to perform, be allowed to enter
    in the amount, and receive an answer. The calculator should be
    comprehensive in that conversions for lengths, areas, volumes, weights, etc.
    should be included."

    I dont want someone to write my code for me, I just want to know the structure or skeleton on which to write this program. How should I start? Feel free to use proper C++ terms, as I am familiar with most of them (classes, structs, functions, etc.) and I use Microsoft Visual Studio 2005. Thanks for your time.

    Chris

  2. #2
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    You mean sort of like this?
    Code:
    double eng;
    cout << "Enter the inches of your object: ";
    cin >> eng;
    double met = eng * 2.54;
    cout << "Your object is "<< met <<" centimeters long."<< endl;

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Describe in detail what you want the program to do. Write out in english what you want the program to do at each step.

    For instance, what operations do you want to calculate?

  4. #4
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Just read his post, he's suppose to make a metric-english converter.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Not what the program is supposed to do
    How the program is supposed to work, step by step! For example, ask the user what he or she wants to convert. Input the number to convert. Ask the user what he/she wants to convert TO, etc.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    17

    Details for converter

    Ok, so I supposed I was somewhat vague in description. Basically, I want to print out a menu of options for the user to select from by choosing the corresponding number next to the option, ie:

    1. Feet to meters
    2. Lbs. to kilograms
    3. Meters to feet
    4. Kilograms to lbs.
    5....
    6....
    7....

    Regardless of what I choose for options, this is the setup I want to obtain. I can do all of the math and actual converting, i just want to know the best/most user friendly way to do it where the user can pick and choose what to get converted from english to metric. Thank you for the fast responses.

    Chris

  7. #7
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    The nicest and most user-friendly would be a pretty GUI, but assuming realistic here...
    Code:
    int main(void)
    {
       int option;
       for(;;)
       {
          cout << "Choose what you want to do..." << endl;
          cout << "1. Feet to meters" << endl;
          cout << "2. Lbs. to kilograms" << endl;
          cout << "3. Meters to feet" << endl;
          cout << "4. Kilograms to lbs." << endl;
          cin >> option;
          // Read my first post!
       }
    }

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    int main(void)
    Code:
    int main()
    This isn't C...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Jan 2008
    Posts
    17
    Ok, so I just create functions for each conversion, but how does the 'option' chosen by the user get referenced to the appropriate function written for the option?

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Your program logic must decide. Easiest would be a switch. A little more advanced would be a function table.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129

  12. #12
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Like this:
    Code:
    int main()
    {
       int option;
       for(;;)
       {
          cout << "Choose what you want to do..." << endl;
          cout << "1. Feet to meters" << endl;
          cout << "2. Lbs. to kilograms" << endl;
          cout << "3. Meters to feet" << endl;
          cout << "4. Kilograms to lbs." << endl;
          cin >> option;
          if(option == 1) Lenght(TRUE);
          else if(option == 2) Weight(TRUE);
          else if(option == 3) Length(FALSE);
          else if(option == 4) Weight(FALSE);
          else break;
       }
       cout << "Goodbye!" << end;
       getch();
    }

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Is that a switch? Last time I looked it wasn't.
    But Yarin, are you going to write the entire program for the OP?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    Registered User
    Join Date
    Jan 2008
    Posts
    17
    I think in my original post i asked to NOT have code written ;-)

  15. #15
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    >> Is that a switch? Last time I looked it wasn't.
    It doesn't need to be a switch. IFs work just fine.

    >> I think in my original post i asked to NOT have code written ;-)
    You asked for a skeleton.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating C/C++ Unit Test Cases
    By chiefmonkey in forum C++ Programming
    Replies: 1
    Last Post: 04-28-2009, 08:29 PM
  2. newbie here.. pls help me in this program!
    By rothj0hn in forum C Programming
    Replies: 2
    Last Post: 02-01-2006, 10:40 PM
  3. 2-d object avoidance. Help please! (basic stuff, I think)
    By charbach007 in forum Game Programming
    Replies: 4
    Last Post: 06-15-2004, 03:49 PM
  4. Unit Actions
    By DavidP in forum Game Programming
    Replies: 20
    Last Post: 05-28-2004, 09:18 PM
  5. Unit Theory - input requested
    By Jeremy G in forum Game Programming
    Replies: 9
    Last Post: 11-18-2003, 10:54 AM