Vector

I want to store 10 names and wieghts in Vector variable, and why this happen. Please help me. tnx

RESULT:
Please enter your name[0]:
ddd dd
Please enter your age[0]:
Please enter your name[1]:
Please enter your age[1]:
Please enter your name[2]:
Please enter your age[2]:
Please enter your name[3]:
Please enter your age[3]:
Please enter your name[4]:
Please enter your age[4]:
Please enter your name[5]:
Please enter your age[5]:
Please enter your name[6]:
Please enter your age[6]:
Please enter your name[7]:
Please enter your age[7]:
Please enter your name[8]:
Please enter your age[8]:
Please enter your name[9]:
Please enter your age[9]:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream>
#include<vector>

using namespace std;

int main(){
        const int max = 10;
        vector<float> weight(max);
        vector<string> name(max);
        int a=0;
        for(a=0; a<max; a++){
                name.at(a)="";
                weight.at(a) = 0.0;
                cout << "Please enter your name[" << a <<  "]: " << endl;
                cin >> name.at(a);
                cout << "Please enter your age[" << a <<  "]: " << endl;
                cin >> weight.at(a);
        }
        return(0);
}
Enter the name must be without spaces
what do i need to accept the spaces?
use separate first and last name
or
read name character by character
can u give me idea how to read character by character.

Tnx
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<vector>

using namespace std;

int main(){
        const int max = 10;
        vector<float> weight(max);
        vector<string> name(max);
		char ch;
        int a=0;
        for(a=0; a<max; a++){
                name.at(a)="";
                weight.at(a) = 0.0;
                cout << "Please enter your name[" << a <<  "]: " << endl;
				cin.get(ch);
				while(ch!='\n')
				{
					name[a].push_back(ch);
					cin.get(ch);
				}
                cout << "Please enter your age[" << a <<  "]: " << endl;
                cin >> weight.at(a);
				cin.get(ch);
        }
		
		system("pause");
        return(0);
}
Wow tnx, it works well.
Topic archived. No new replies allowed.