I've been bashing my head against these drills for days and I can't grasp them.
I have to add a unit to my numbers (i.e m,ft,in,cm.) and reject invalid units, then convert the numbers and units into metres.
I have my code that shows how to choose and keep the highest and lowest numbers etc, but i'm at a complete loss as to how to add the unit part, i've tried if statements and they seem to look like they'll work, but then they don't and i get frustrated and it honestly bugs me that i've missed some fundamental point.
here is my code so far
int main(){
double val1=0;
string unit;
double large=0;
double small=0;
cout<<"please Enter 1 number and a unit (cm, M, Ft, In):\n";
while (cin>>val1>>unit){
if(val1<small) {small=val1; cout<<"smallest so far\n";}//find smallest number
else if(val1>large) {large=val1; cout<<"largest so far\n";}//Find largest number
else cout<<"Neither largest nor smallest\n";
}
cout<<"The smaller value so far is (in metres): "<<small<<"\n";
cout<<"The larger value so far is (in metres): "<<large<<"\n";
keep_window_open("~");
return 0;
}
It's not homework and I'm only doing this for my own interest. any help would be appreciated.