#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int person;
cout << "How many person to data: ";
cin >> person;
int x = 0;
int i = 1;
string name[person];
string adress[person];
while(x < person){
cout << i << " person data" << endl;
cout << "Name: ";
getline(cin, name[x]);
cout << "Adress: ";
getline(cin, adress[x]);
cout << endl;
x++, i++;
}
for(x=0; x<person; x++){
cout << name[x] << setw(15) << adress[x] << endl;
}
}
This is my code to store a name and an adress into an array name[] and adress[] And then i use for loop to print their name and adress
This is output image Result
Why is my 1 person data broken? The name and adress is on the same line while my 2nd person data is fine?
Its fine if i use cin >> but i use getline so i can a full name and an adress with the spaces