Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8422009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:18:53+00:00 2026-06-10T03:18:53+00:00

Below is my do while loop with cin There a bit of problem, when

  • 0

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: some_email@gmail.com

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=="");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:18:54+00:00Added an answer on June 10, 2026 at 3:18 am

    Instead of if(counter>0) use if(counter==0)

    My working test app:

    int counter = 0;
    string fullname, emailAddress;
    do
    {
      if(counter==0)
      {
         //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: ";
      }
    
      getline(cin,emailAddress);
      counter++;
    } while (emailAddress=="");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am prompting the user to enter data regarding cars. The Do...while() loop I
As you can see below, I have Parallel.For loop. If run the program while
I am facing problem while setting focus in EdiText. Below is my EditText property.
I have put together the following code, the problem is that each while loop
I've got a C program that encounters errors when I enter a while loop.
I have code below that is getting called from a while loop so it's
I am using the code below Thread.Sleep(5); at the end of a while loop.
The problem for me nothing gets executed after while loop? what's the issue with
If user key in letter like a , it will result in endless loop,
as before the below code is in a while loop . it out puts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.