Unit converter calculator help

This is a discussion on Unit converter calculator help within the C++ Programming forums, part of the General Programming Boards category; Greetings all, I am a senior Industrial Engineer major at Wayne State University in Detroit, MI who took a 1000 ...

  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
    1,534
    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;
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  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
    1,534
    Just read his post, he's suppose to make a metric-english converter.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,175
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  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
    1,534
    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!
       }
    }
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,175
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,175
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

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

  12. #12
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,534
    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();
    }
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  13. #13
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,175
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  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
    1,534
    >> 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.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

Page 1 of 2 12 LastLast
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, 09: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, 09:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21