I was practicing the use of getline()
in my code. But in the second while loop, I can't enter an input. It jumps to "Press [1] to Continue". I'm thinking if I can only use getline()
once. Please help me to solve the bug
string name[100];
string address[100];
int timesName = 0;
int timesAddress = 0;
int option;
int i = 1, j = 1;
while (i != 0) {
cout << "Enter Name: " << endl;
getline(cin, name[timesName]);
cout << "Press [1] to Continue" << endl;
cout << "Press [2] to Stop" << endl;
cin >> option;
if (option == 1) {
i = 1;
timesName++;
} else {
i = 0;
}
}
while (j != 0) { // SECOND WHILE LOOP
cout << "Enter Address: " << endl; // this is where the bug occur
getline(cin, address[timesAddress]);
cout << "Press [1] to Continue" << endl;
cout << "Press [2] to Stop" << endl;
cin >> option;
if (option == 1) {
j = 1;
timesAddress++;
} else {
j = 0;
}
}