Created
January 25, 2012 21:25
-
-
Save weatheredwatcher/1678814 to your computer and use it in GitHub Desktop.
Create a person...a fun little coding with my daughter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
struct person_t { | |
string name; | |
int age; | |
} mine, yours; | |
void printperson (person_t person); | |
void compare_us(); | |
int main (){ | |
string mystr; | |
mine.name = "David"; | |
mine.age = 30; | |
cout << "What is your name?: "; | |
getline (cin,yours.name); | |
cout << "How Old Are You?: "; | |
getline (cin,mystr); | |
stringstream(mystr) >> yours.age; | |
cout << "My name is:\n "; | |
printperson (mine); | |
cout << "And your name is:\n "; | |
printperson (yours); | |
compare_us(); | |
return 0; | |
} | |
void printperson (person_t person){ | |
cout << person.name; | |
cout << " (" << person.age << ") \n"; | |
} | |
void compare_us(){ | |
int difference = mine.age - yours.age; | |
cout << "I am " << difference << " years older!"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment