Unit converter calculator help

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 01-13-2008
ravens199
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
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
• 01-13-2008
Yarin
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;```
• 01-13-2008
robwhit
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?
• 01-13-2008
Yarin
Just read his post, he's suppose to make a metric-english converter.
• 01-13-2008
Elysia
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.
• 01-13-2008
ravens199
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
• 01-13-2008
Yarin
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!   } }```
• 01-13-2008
Elysia
Code:

`int main(void)`
Code:

`int main()`
This isn't C...
• 01-13-2008
ravens199
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?
• 01-13-2008
Elysia
Your program logic must decide. Easiest would be a switch. A little more advanced would be a function table.
• 01-13-2008
robwhit
• 01-13-2008
Yarin
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(); }```
• 01-13-2008
Elysia
Is that a switch? Last time I looked it wasn't.
But Yarin, are you going to write the entire program for the OP? :p
• 01-13-2008
ravens199
I think in my original post i asked to NOT have code written ;-)
• 01-13-2008
Yarin
>> 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 ;-)