I'm trying to make a program in which the user enters in a number and a letter representing what unit of measurement their using (ex inches=i, feet=f, etc) then the letter inputted is used on a series of if statements to see which function to go to convert the number to how many meters it would be. I added an input validation for the units of measure(which are being used as a string variable).My problem is when I input the letter I want to use the program thinks what I entered is invalid even when the input is correct. I removed the input validation and also noticed that the string doesn't even go through any of the if statements. The code is something like this the #include included:
#include <iostream>
#include <string>
using namespace std;
float inTOmeters(float);
float ftTOmeters(float);
float cmTOmeters(float);
float yTOmeters(float);
int main{
float measurement, measurement;
string unit;
cout<<"Enter the number you want to be measured"<<endl;
cin>>measure;
cout<<"Now enter the unit of measurement you want to use"<<endl;
cout<<"i=inches, f=feet, c=centimeters, y=yards, m=meters"<<endl;
cin<<unit;
while(unit !="i"||unit !="m"||unit !="c"||unit !="y"||unit !="f"){
cout<<"Invalid input pick from I, m, c, y, or f"<<endl;
cin>>unit;
}
if(unit=="i"){
measurementm=inTOmeters(measurement);
}
if(unit=="c"){
measurementm=cmTOmeters(measurement);
}
if(unit=="f"){
measurementm=ftTOmeters(measurement);
}
if(unit=="y"){
measurementm=yTOmeters(measurement);
}
else{
measurementm=measurement;
}
cout<<"your measurement will be"<<measurementm<<"in meters."<<endl;
}
I didn't include the functions because I know they work. My question is how do I make it so my loop and if statements function when given the correct input? Also how do I make it so the code accepts capital letters of the correct input?