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);
}
|