[php]
#include <iostream>
#include <string> // including the string.h file
#include <sstream> // including the stringstream
using namespace std;
int main()
{
string ITSASTRING; // empty string, used for transfering variables
string firstname; // second string, used for first name
string lastname; // third string, used for last name
int age; // int, used for age
cout << "Hi, what is your FIRST name?" << endl;
getline (cin,ITSASTRING); // getting the input from this line and inputting it into ITSASTRING
stringstream(ITSASTRING) >> firstname; // transferring data from ITSASTRING to firstname
cout << "Alright " << firstname << " what is your last?";
getline (cin,ITSASTRING); // getting the input from this line and inputting it into ITSASTRING
stringstream(ITSASTRING) >> lastname; // transferring data from ITSASTRING to lastname
cout << "alrighty then " << firstname<<" " <<lastname <<", how old are you?" << endl; // displaying firstname lastname and asking how old
cin >> age; // the usual cin >> age
if (age >= 18) { // if age is equal to or less then 18 do the following
cout << "Hi " << firstname<< " " <<lastname << ", welcome to my application!"<< endl;
}
else { // age was more then 18 so we do the following
cout << "Hi " << firstname<<" " <<lastname <<", sorry but you are not old enough for my application." << endl;
}
cin.get(); // waiting for input from user
return 0; // returning 0 to int main
// yes, I did explain a lot. But other people may read this and not understand it, so I felt it was important.
}[/php]
[php]
#include <iostream>
#include <string> // including the string.h file
#include <sstream> // including the stringstream
using namespace std;
int main()
{
string ITSASTRING; // empty string, used for transfering variables
string firstname; // second string, used for first name
int age; // int, used for age
cout << "Hi, what is your FIRST name?" << endl;
getline (cin,ITSASTRING); // getting the input from this line and inputting it into ITSASTRING
stringstream(ITSASTRING) >> firstname; // transferring data from ITSASTRING to firstname
cout << "alrighty then " << firstname<<" how old are you?" << endl; // displaying firstname and asking how old
cin >> age; // the usual cin >> age
if (age >= 18) { // if age is equal to or less then 18 do the following
cout << "Hi " << firstname<< ", welcome to my application!"<< endl;
}
else { // age was more then 18 so we do the following
cout << "Hi " << firstname<< ", sorry but you are not old enough for my application." << endl;
}
cin.get(); // waiting for input from user not required with microsoft visual c++
return 0; // returning 0 to int main
// yes, I did explain a lot. But other people may read this and not understand it, so I felt it was important.
}[/php]
1st code can be used for both names, second code can be used for just the first name.
Both of these work 100% for microsoft visual c++ 2010, my way teaches, korean's is simple. Although, for me, cin >> wasn't working properly anyways...