Question

Write a C++ program which will prompt the user to enter the name and age of...

Write a C++ program which will prompt the user to enter the name and age of 10 persons and print the name and age of the oldest person and the name and age of the youngest person (This program must use the repetition control structure.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<string.h>
using namespace std;


int main(){
int age[10];
string name[10];
int max;
int min;
for(int i=0;i<10;i++){ // taking input
cout<<"Enter Name: ";
cin>>name[i];
cout<<"Enter age: ";
cin>>age[i];
if(i==0){
max=i;
min=i;
}else{ // for comparing the max and min
if(age[max]<age[i]){ // if current max is less than entered max update
max=i;
}
if(age[min]>age[i]){ // if current min is greater than entered update min
min=i;
}
}
}

cout<<"Youngest person: "<<endl;
cout<<"name: "<<name[min]<<endl;
cout<<"age: "<<age[min]<<endl;

cout<<"Oldest person: "<<endl;
cout<<"name: "<<name[max]<<endl;
cout<<"age: "<<age[max]<<endl;
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write a C++ program which will prompt the user to enter the name and age of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT