Advertisement

06.08.2008 at 06:10PM PDT, ID: 23467840
[x]
Attachment Details

Using array vector for name and age

Asked by jschmuff in C++ Programming Language, Programming Languages

Tags: C++

I am doing this exercise in my book. well it is a little modified but same gist. I want to take in 10 names and ages which I have done. But now I want to list the names of the people over 21, but I cannot find that in the chapter anywhere on how I can do this to me it seems like they wouldn't be linked since one is of type string and the other of type int.

Here is what I have so far: (Any ideas on this would really help me out I am just trying to understand these vectors better, but find them rather confusing.)

Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
#include <iostream>
#include <vector>
#include <string>
 
using namespace std;
 
vector<string> names;
vector<int> ages;
 
int main()
{
	int const SIZE = 10;
	string name;
	int age;
 
	for (int i = 0; i < SIZE; i++)
	{
		cout << "Enter name: ";
		cin >> name;
		names.push_back(name);
		cout << "Enter Age: ";
		cin >> age;
		ages.push_back(age);
	}
 
	for (int i = 0; i < SIZE; i++)
	{
		cout << "Student Name: " << names[i] << " Age: " << ages[i] << endl;
	}
 
}
 
Loading Advertisement...
 
[+][-]06.08.2008 at 07:23PM PDT, ID: 21740599

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C++ Programming Language, Programming Languages
Tags: C++
Sign Up Now!
Solution Provided By: efn
Participating Experts: 1
Solution Grade: A
 
 
[+][-]06.08.2008 at 07:28PM PDT, ID: 21740637

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.08.2008 at 07:32PM PDT, ID: 21740688

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.08.2008 at 07:44PM PDT, ID: 21740763

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.08.2008 at 07:48PM PDT, ID: 21740816

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628