Skip to content

Instantly share code, notes, and snippets.

@weatheredwatcher
Created January 25, 2012 21:25
Show Gist options
  • Save weatheredwatcher/1678814 to your computer and use it in GitHub Desktop.
Save weatheredwatcher/1678814 to your computer and use it in GitHub Desktop.
Create a person...a fun little coding with my daughter
#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