Mar 10, 2014 at 4:44am UTC
Alright so I want to have the data entered and then during the next two steps I want the string data to be turned into int then double but I cant figuer out how to do it I have tried atoi and atof but when i do it nothing happens
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
#include <iostream>
#include <string>
using namespace std;
string Udata;
void divider(), divider2(), divider3();
void welcome();
string getInput();
int main ()
{
for (int i = 0; i < 3; i++)
{
if ( i == 0)
{
divider();
getInput();
cout << Udata <<endl;
system("pause" );
}
else if (i == 1)
{
divider2();
getInput();
cout<<"two" << endl;
char buffer[256];
fgets (buffer, 256, stdin);
Udata = atoi (buffer);
printf ("The value entered is %d. Its double is %d.\n" ,Udata);
system("pause" );
}
else if (i == 2)
{
divider3();
cout<< "one" << endl;
system("pause" );
}
}
}
void divider()
{
cout << "\n**************** GET NAME ****************" << endl;
}
void divider2()
{
cout << "\n**************** GET AGE ****************" << endl;
}
void divider3()
{
cout << "\n**************** GET MILEAGE ****************" << endl;
}
}
string getInput()
{
getline(cin,Udata);
return Udata;
}
Last edited on Mar 10, 2014 at 4:51am UTC
Mar 10, 2014 at 5:53am UTC
Thank you thats help alot ^^