need to put strings into arrays

javascript:tx('quote')
void family ()
{
string father;
string mother;
string kids;
int x;
int y=0;
int i=1;
char f[100];

cout <<"write the name of the father ";
cin >> father;
cout <<"write the name of the mother ";
cin >>mother;
cout <<"write the numbers of the kids";
cin >>x;
do
{
cout <<"write the kid name" ;
cin >> kids;
i++ ;
}
while (i<=x);
}
javascript:tx('quote')
how am i allowed to but the 3 strings father, mother and kids in a array?
The only array you have there is an array of characters; did you want an array of strings instead?
yes, can you explain how this can be done
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
#include<iostream>
#include<string>           // add this
using namespace std;

void family ()
{
string father;
string mother;
//string kids;  //remove this    
int x;
int y=0;
int i=0;//change this
char f[100];

cout <<"write the name of the father ";
cin >> father;
cout <<"write the name of the mother ";
cin >>mother;
cout <<"write the numbers of the kids"; 
cin >>x;
string kids[x];    // add this
do
{
cout <<"write the kid name" ;
cin >> kids[i];  //change this
i++ ;
}
while (i<x);   //change this 
}


now enjoy your code
Last edited on
Topic archived. No new replies allowed.