I'm trying to write a program which takes measurements from a user and inputs them into a vector. The while loop continues until the user inputs '|' at which point it breaks out of the loops and prints the measurements. The problem I am having however is that when trying to add the measurements to the vector. I have used the debugger and found that the loops never actually enters the for loop, thus not being able to reach the "push_back statement".
This program is part of the drills in the Bjarne Stroustup PPP c++ book.
#include "../../std_lib_facilities.h"
double metreConvert (double userInput , String unit) {
if (unit == "cm")
userInput = userInput / 100;
else if (unit == "in")
userInput = (userInput * 2.54) / 100;
else if (unit == "ft")
userInput = ((userInput * 12) * 2.54) / 100;
else if (unit == "m")
userInput;
return userInput;
}
void numbers() {
double input;
String unit;
vector <double> measurements;
while (cin >> input >> unit && input != '|'){
if (unit == "cm")
input = input / 100;
else if (unit == "in")
input = (input * 2.54) / 100;
else if (unit == "ft")
input = ((input * 12) * 2.54) / 100;
else if (unit == "m")
input;
for (int i=0; measurements.size(); i++){
if (i == 0 || input != measurements[i]){
cout << "\nPopping onto vector";
measurements.push_back(input);
}
else {
cout << "\nMeasurment cannot be placed on vector";
}
}
}
cout << "input ended";
}
void main() {
cout << "Please enter a number followed by a unit(metres,cm,inches,ft), type '|' when finished inputing:";
numbers();
}
input;just before theforloop do?