Help With A Game

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.

Thanks, Travis
Last edited on
closed account (j3Rz8vqX)
changing a string to say something else
Converting a string to a numeric or reassigning it a string?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <cstdlib>      //For use of atof() function
#include <sstream>      //For use of stringstream object
using namespace 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;
}

http://www.cplusplus.com/reference/cstdlib/atof/
http://www.cplusplus.com/reference/sstream/stringstream/
Topic archived. No new replies allowed.