Hi guys please check this code. I want to create a program in which I will be prompted to enter first name and last name then output it in chronological order without having to create variable for each first name and last name.
#include<iostream>
using namespace std;
int main(){
int fname[9];
int lname[9];
int x;
while (x < 10){
cout<<"Enter first name: ";
cin>>fname[0];
cout<<"Enter last name: ";
cin>>lname[0];
x = x + 10;
}
x = 0;
while (x < 10){
cout<<fname[0]<<" "<<lname[0]<<"\n";
x = x + 1;
}
return 0;
}
intarrays for text input?while (x<10){ /*...*/ x = x+10;}will execute exactly once. Also the secondwhileloop is broken: You write the same stuff 10 times.std::vector<std::string>>and please dont abusewhileloops when a simpleforloop would be much clearer