# Thread: Unit converter calculator help

1. ## 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. 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. 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. Just read his post, he's suppose to make a metric-english converter.

5. 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.

6. ## 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. 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. Code:
`int main(void)`
Code:
`int main()`
This isn't C...

9. 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. Your program logic must decide. Easiest would be a switch. A little more advanced would be a function table.

11. 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();
}```

12. Is that a switch? Last time I looked it wasn't.
But Yarin, are you going to write the entire program for the OP?

13. I think in my original post i asked to NOT have code written ;-)

14. >> 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