Hi, I am new to c++ and i just started making a text based game but I am stuck and don't know what to do about changing a string to say something else. If anyone can help me, please e-mail me at travis.bonneau@yahoo.com.
#include <iostream>
#include <cstdlib> //For use of atof() function
#include <sstream> //For use of stringstream object
usingnamespace std;
float validate(float value, string aString)
{
stringstream ss;
ss<<value;
if(aString==ss.str())
return value;
return 0;
}
int main ()
{
string aString;
cout<<"String to float program (with validation)\n\n";
do
{
cout<<"\nEnter a numeric string ('exit' to break loop): ";
getline(cin,aString); //Re-assigning the string a new value
cout<<"Its numeric representation would be: "<<endl;
cout<<": '"<<aString<<"' == "<<validate(atof(aString.c_str()),aString)<<endl; //Print string and converted float string
}while(aString!="exit");
return 0;
}