class program to read two and print one

may i need ur help in this Program, im stuck in this program.

>>
a class program to read in a persons names address and age of two ppl and print out the plder person.
the program shud print out the name, address and age of elder person and also it shud prit out the age differnce.

>>>

i ll b very greatefull 4 for ur help.
thanks
The best option here is to:

1.Create a struct with all this information

1
2
3
4
5
struct struct1{ 
     string lastName;
     string firstName;
     int age;
} Person;


2.Create an array (size 2)(same file type as the stuct) and input the neccisary information.

1
2
3
4
struct1 array1[2];
cin>>array[0].lastname;
cin>>array[0].firstname;
ect.


3. a simple bubblesort on the array should sort age from youngest to oldest.
4. print out the second array spot.
5. Then just subract the first array from the second.

cout<<array[1].age - array[0].age;

If you don't understnad this, you can do it with a crapload of if statements and loops, but this way will make your code look better.
Last edited on
Topic archived. No new replies allowed.