42.0k views
4 votes
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.

1 Answer

1 vote

Answer:

#include <iostream>

#include <iomanip>

#include <string>

using namespace std;

int main() {

string name[5];

int age[5];

int i,j;

for ( i = 0; i<=4; i++ ) {

cout << "Please enter student's name:";

cin >> name[i];

cout << "Please enter student's age:";

cin >> age[i];

}

for (i=0;i<=4;i++){

cout<<"Age of "<< name[i]<<" is "<<age[i]<<endl;

}

}

Output of above program is displayed in figure attached.

Create two arrays with 5 elements each: one will hold Strings and the second will-example-1
User Jenix
by
4.2k points