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 7728907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:50:08+00:00 2026-06-01T05:50:08+00:00

Its been a while since i have coded c++ and i have forgot an

  • 0

Its been a while since i have coded c++ and i have forgot an annoying thing that happens when you gather string input. Basically if this loops back through, say if you use negative numbers then it skips the cin from the employee name line the second go round. I remember having this issue before and having to clear or do something of that sort before or after the string is input. Please help!

PS Also for extra help can anyone help me with a correct loop below. How can i check for a value in the string input to make sure they input a value?

#include <string>
#include <iostream>
#include "employee.h"

using namespace std;

int main(){

    string name;
    int number;
    int hiredate;

    do{

        cout << "Please enter employee name: ";
        getline(cin, name);
        cout << "Please enter employee number: ";
        cin >> number;
        cout << "Please enter hire date: ";
        cin >> hiredate;

    }while( number <= 0 && hiredate <= 0 && name != "");

    cout << name << "\n";
    cout << number << "\n";
    cout << hiredate << "\n";

    system("pause");
    return 0;
}
  • 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-01T05:50:09+00:00Added an answer on June 1, 2026 at 5:50 am

    You want to change your loop condition to be whether or not any of the below are not set. The logical AND will only trigger if all three are unset.

    do {
        ...
    } while( number <= 0 || hiredate <= 0 || name == "");
    

    Next, use cin.ignore() as prescribed by @vidit to get rid of issues with reading in newline characters.

    Lastly, and importantly, your program will run an infinite loop if one enters an alphabetic character for an integer instead of…an integer. To mitigate that, use isdigit(ch) from the <cctype> library.

     cout << "Please enter employee number: ";
     cin >> number;
     if(!isdigit(number)) {
        break; // Or handle this issue another way.  This gets out of the loop entirely.
     }
     cin.ignore();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Its been a while since I had to do some Java/JSP... I have a
its been I while since I try to solve that problem, I've already asked
Its been a long time since I have programmed in C++, but I know
Its been a while since I've done any hard core web design, so I
It's been a while since I last coded arm assembler and I'm a little
Its been a while since I worked in asp.net and a very long time
Ok, its been a while since I've worked with a Web References. I need
It's been a while since I have had to write C++ code and I'm
It's been a while since I last did Ruby programming -- looking at somebody
It's been a while since I've messed with .htaccess and I can't seem to

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.