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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:50:08+00:00 2026-05-14T03:50:08+00:00

Example user input: PA1 9 //correct PJ1 9 //wrong, error printed Invalid row because

  • 0

Example user input:

PA1 9 //correct 
PJ1 9 //wrong, error printed "Invalid row" because it is not between A and I 
PA11 9 //wrong, error printer "Invalid column" because it is not between 1 and 9.

The problem I am having is that it should clear the remaining input and then ask for the user to enter the “move” again, and it is not.

Where did I go wrong? I’ve been at it for a while and still got no progress..

void clearInput()
{ 
 cin.clear();
}

bool getCoords(int & x, int & y)
{
 char row;

 while(true){
 cin>>row>>y;
 row=toupper(row);

 if(/*(id=='P' || id=='p' || id=='D' || id=='d') &&  */row>='A' && row<='I' && isalpha(row)  && y>=1 && y<=9){ 
     x=row-'A';
  y=y-1; 
  return true;
 }

 else if(!(y>=1 && y<=9)){
  cout<<"Invalid column\n"<< endl << endl;
  cout<<y;
  clearInput();
  cout<<y;
  //return false; 
 }
 else{
  cout<<"Invalid row\n"<< endl << endl;
  clearInput(); 
  //cout<<x<<y;
  //return false;
 }
 }
}
  • 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-05-14T03:50:08+00:00Added an answer on May 14, 2026 at 3:50 am

    cin‘s clear member function doesn’t clear the remaining input, it resets the error flags on the stream (which could get set e.g. because you tried to read an integer but there were non-digit characters in the input). I guess you really want to discard the input up to the next newline; one way to do this would be to call cin.ignore with ‘\n’ as the delimiter.

    Another thing that could be an issue (but might just be code left out in the question ;)) is that the while(true) loop that you’ve written to repeatedly ask for input until there’s no error doesn’t contain the board-redrawing logic you talk about in your comment. So you won’t see this until the getCoords function finds error-free input and returns.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to detect user input character in UITextView? For example:(in UITextView NOT UITextField) when
to sanitize user input we usually use mysql_real_escape_string, but for example if i want
I need to escape just part user input for output. For example Hey a
In JavaScript, I'm trying using the user's input to search my database. For example,
You have a user input string from a textbox for example var strInput =
For example, if the user input the url like http://site.com/controller. php , I want
What part in the MVC does user input get validated? For example, user registration
I want remove repeating character if more than 2 on user input, example heloooo!!!!!!!!
What is the best character to use to delimit user input? For example if
Example user input http://example.com/ http://example.com/topic/ http://example.com/topic/cars/ http://www.example.com/topic/questions/ I want a PHP function to make

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.