Below is my do while loop with cin There a bit of problem, when user enter Fullname then press enter. The pointer will go to next line. until user press enter again, then it prompt Email address, how do i make it prompt email address right after full name is entered on my code below
Terminal Look:
Full Name: John
Email Address: [email protected]
My test.cpp code:
emailAddress= "";
fullname = "";
counter = 0;
if(department_selection!="")
{
while(fullname=="")
{
if(counter>0)
{
//so it wont print twice
cout << "Full Name: ";
}
getline(cin,fullname);
cin.clear();
cin.ignore();
counter++;
}
counter = 0;
while(emailAddress=="")
{
if(counter>0)
{
//so it wont print twice
cout << "Email Address: ";
}
getline(cin,emailAddress);
cin.clear();
cin.ignore();
counter++;
}
}// if department selection not blank
Still same issue. i need to tab enter once then it prompt for email address.
Latest Update: Manage to fix it. I make changes to the code and it is this version:
do
{
if(counter==0)
{
//so it wont print twice
cout << "Full Name: ";
}
if(counter>1)
{
//so it wont print twice
cout << "Full Name: ";
}
getline(cin,fullname);
counter++;
} while (fullname=="");
counter = 0;
do
{
if(counter==0)
{
//so it wont print twice
cout << "Email Address: ";
}
if(counter>1)
{
cout << "Email Address: ";
}
getline(cin,emailAddress);
counter++;
} while (emailAddress=="");