Create two arrays with 5 elements each: one will hold Strings and the second wil
ID: 664269 • Letter: C
Question
Create two arrays with 5 elements each: one will hold Strings and the second will hold integers.
Write a program to ask the user to enter 5 student names and their ages. Output the data from the parallel arrays.
Sample Run: Your program must run exactly like the example below.
Enter a student name: Joe
Enter a student name: Mark
Enter a student name: Mary
Enter a student name: Michelle
Enter a student name: Aaron
Enter Joe’s Age: 25
Enter Mark’s Age: 24
Enter Mary’s Age: 35
Enter Michelle’s Age: 19
Enter Aaron’s Age: 65
Joe 25
Mark 24
Mary 35
Michelle 19
Aaron 65
Explanation / Answer
#include <iostream.h>
void main() {
char Student[5][20] = { "Joe", "Mark", "Mary", "Michelle", "Aaron" };
int ages[5] = { 25, 24, 35, 19, 65 };
for(int x = 0; x < 5; x++) {
cout << Student[x] << " " << ages[x] << endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.