howdy,
this code is an atempt to get user input and check to make sure it is the correct type.
#include <iostream.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <typeinfo>
float ftoi();
int main()
{
float ts;
// ftoi();
ts = ftoi();
cout <<"ts = " <<ts<<"\n";
cout <<"ts doubled = "<<ts*2<<"\n";
}
float ftoi()
{
//the first thing is to convert from feet to inches
system ("clear");
int feet = 0; //set feet to zero
double inches = 0; //set inches to zero
double total_span = 0;
char t;
cout <<"Enter FEET of bridge span: "; //whole feet of bridge span
cin >> feet;
t = feet;
if (typeid(t).name() != "int"){
//cout<<"You must enter feet as a digit\n";
cin>>feet;
}
cout <<"\nEnter INCHES with fraction(ie 6.38)of bridge span: "; //inches span
cin >> inches;
feet = feet*12; //convert feet to inches
total_span = feet + inches; //add feet & inches
cout <<"\nThe Total span is "<<total_span<<" inches\n";
return total_span;
}
the "typeid(t).name()" thing seems to catch the char types however it just falls through and exits.
what is a better way of checking user input for correct type.
Thanks
M.R.