Converting string to float with atof() in C++
I'm new to C++ and I need help converting my string variable into a
number. I need to print the person's age and her next year age on the
screen but I can't figure out how. I can't use the string to do math. So
can you please shoot me a couple examples please?
I tried to do it this way:
//converts F to C
ctemp=(ftemp-32)*5.0/9.0;
//calculates age
age2 = age + 1 ; age2 = atof (age2.c_str()); age = atof (age.c_str());
cout<<name<<" is "<<age<<" now, and will be " <<age2<<" a year from
now.\n"<<"Its "<<ftemp<<" in "<<city<<"--- That's
"<<setprecision(2)<<ctemp<<" degrees C"<<endl;
No comments:
Post a Comment