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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  #include <iostream>
#include <string>
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.