Question & Answer: Write C++ code to convert a string variable named number to a float and then increment the float value by 1 and print the result……

Write C++ code to convert a string variable named number to a float and then increment the float value by 1 and print the result.

For example:

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: Write C++ code to convert a string variable named number to a float and then increment the float value by 1 and print the result……
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay
Test Result
string number = "180.56";
181.56
string number = "-0.456";
0.544

Expert Answer

 

#include <iostream>

using namespace std;

int main()
{
string number=”100.1″;
float floatval;
floatval=strtof((number).c_str(),0) ;
floatval++;
cout<<“float value is:”<<floatval;

return 0;
}

output:

Question & Answer: Write C++ code to convert a string variable named number to a float and then increment the float value by 1 and print the result...... 1

/* the string variable number is conveted to float
by using functions of library
and incremented by one
and result is printed on screen
note :please check that it prints one decimal after points
*/

Still stressed from student homework?
Get quality assistance from academic writers!