Display all values in a vector?/If statements negated

I'm having a bit of trouble here on how to display all values in a vector
without going one at a time. Also, my if statements are being canceled out for some reason. The if statements at the bottom are for testing inputs that come in between and count all inputs. They're completely ignored when I run the progrma.
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

while (cin >> input >> unit)			
// Centimeters
if (unit == "cm" && input*mm_per_cm > large_converter){
	largest_input = input;
	largest_unit = unit;
	large_converter = input*mm_per_cm;
	cout << "\n";
	cout << "Largest so far is " << largest_input << largest_unit << endl;
	cout << "\n";
	input_storage.push_back(input*0.01);
	}
else if (unit == "ft" && input*mm_per_ft < small_converter){
        smallest_input = input;
        smallest_unit = unit;
	small_converter = input*mm_per_ft;
	cout << "\n";
	cout << "Smallest so far is " << smallest_input << smallest_unit << endl;
	cout << "\n";
	input_storage.push_back(0.33);
			}   
	else if (unit == "cm"){
	        ++num_of_inputs;
		sum_of_inputs += input*mm_per_cm;
		}
	else if (unit == "in"){
	       ++num_of_inputs;
	       sum_of_inputs += input*mm_per_in;
	}
	else if (unit == "ft"){
	       ++num_of_inputs;
	       sum_of_inputs += input*mm_per_ft;
	}
        else if (unit == "m"){
	       ++num_of_inputs;
	       sum_of_inputs += input*mm_per_m;
	}
}
Only one if/else if block can be executed. If condition is met in one of the first two ifs, the rest of the block is skipped. Didn't you mean to start another block of if/else in line 22?.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
while (cin >> input >> unit)
// Special cases
if (unit == "cm" && input * mm_per_cm > large_converter) {
	//...
}

else if (unit == "ft" && input * mm_per_ft < small_converter) {
	// ...
}

/// Restart if from here for general cases
if (unit == "cm") {
	// ...
}
else if (unit == "in") {
	// ...
}
else if (unit == "ft") {
	// ...
}
else if (unit == "m") {
	// ...
}


To display all values in a vector you must access them one at a time, best in a for loop
for (int i = 0; i < vector.size; i++){/*display vector[i] */}
Last edited on
Topic archived. No new replies allowed.