### A mess. Literally.

After a while of messing around while trying to get the smallest to largest double to show it finally worked. There is one bug though. The first value always says 0 is the smallest number. Other than that it works like a charm.
The true problem is trying to do this with units of measurement. I just
can't find a way to do this... This is my horrible attempt of trying to piece
it together and show the number a long side it's unit of measurement.
Would anyone be so kind as to show me this in the simplest way possible?
I'm doing this from a book so I have to learn how to do it the hard way before
I move on to my lesson on vectors etc. So if, while, for, else, etc will
be a big help instead of all the other things I don't even understand yet.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677`` `````` #include #include using namespace std; int main () { double entered = 0; double previous = 0; double largest = 0; double smallest = 0; double base = 0; char unit = '?'; char previous_unit = '?'; char smallest_unit = '?'; char largest_unit = '?'; char m; char cm; char in; char ft; double s_unit_ft_to_ft = smallest * 1; double s_unit_in_to_in = smallest * 1; double s_unit_m_to_m = smallest * 1; double s_unit_cm_to_cm = smallest * 1; double s_unit_m_to_cm = smallest * 100; double s_unit_in_to_cm = smallest * 2.54; double s_unit_ft_to_in = smallest * 12; double s_unit_ft_to_cm = smallest * 30.48; double s_unit_ft_to_m = smallest * 0.3048; double s_unit_m_to_in = smallest * 0.0254; double l_unit_ft_to_ft = largest * 1; double l_unit_in_to_in = largest * 1; double l_unit_m_to_m = largest * 1; double l_unit_cm_to_cm = largest * 1; double l_unit_m_to_cm = largest * 100; double l_unit_in_to_cm = largest * 2.54; double l_unit_ft_to_in = largest * 12; double l_unit_ft_to_cm = largest * 30.48; double l_unit_ft_to_m = largest * 0.3048; double l_unit_m_to_in = largest * 0.0254; cout << "Input a number followed by a unit. I shall show the largest and smallest out of all." << endl; cout << "--------------------------------------Unit Key--------------------------------------" << endl; cout << "Meter = m"; cout << "\n"; cout << "Centimeter = cm"; cout << "\n"; cout << "Inch = in"; cout << "\n"; cout << "Feet = ft"; cout << "\n"; cin >> base; cout << "Input unit for this number" << endl; cin >> unit; previous = base; previous_unit = unit; while (cin >> entered) { if (entered < base, unit == 'm'){ base = entered; smallest = entered; smallest_unit = unit; cout << "Smallest so far is " << smallest << smallest_unit << endl; cout << "Largest so far is " << largest << largest_unit << endl; } if (entered > previous){ largest = entered; previous = entered; largest_unit = unit; cout << "Smallest so far is " << smallest << smallest_unit << endl; cout << "Largest so far is " << largest << largest_unit << endl; } } } ``````
Not quite sure what you are trying to do here. Are you trying to output the biggest number of those entered? Or relative to the unit of measure?

Expound, please.
Largest and smallest number with units of measurement.
Like superdude, I don't know what you're trying to do. If you give us more info or maybe post the example from the book, we'd be able to help more.

Some things I see from looking at your code:

unit, m, cm, in, ft, previous_unit, smallest_unit and largest_unit are of type `char`, which means they can only hold one character.

Lines 21-41 are not equations as you might think, they are assignments.
This is a problem that a lot of new comers seem to stumble into, as they can get some familiar mathematical concepts confused with programming concepts.
By your logic, the following would be impossible :
`i = i + 1;`
It's not an equation, it's an assignment.

Also, `int main()...` is not returning anything.
Last edited on
Topic archived. No new replies allowed.