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

  • Home
  • SEARCH
  • 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 3345016
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:08:12+00:00 2026-05-18T01:08:12+00:00

i saw an unusual problem in this code: #include <iostream> using namespace std; int

  • 0

i saw an unusual problem in this code:

#include <iostream>
using namespace std;

int main()
{
 int number;
 bool repeat=true;

 while (repeat)
 {
  cout<<"\nEnter a number:";
  cin>>number;
  cout<<"\nNumber is:"
   <<number;
  cout<<"\nRepeat?:";
  cin>>repeat;
 }
 system("pause");
 return 0;
}

here in this code when i put a character such “A” in int type variable while loop repeats over and over and don’t ask me whether to repeat or not.
this problem just appear when i put characters not integers.
this appears with for too.

why should happen this?
thanks

  • 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-18T01:08:13+00:00Added an answer on May 18, 2026 at 1:08 am

    After reading in user input which cannot be converted, the input stream is in an invalid state. You need to empty the stream and call the clear method to reset the error bits on the stream in order to resume normal operation.

    If you detect that input was not successful (using the input streams state bits, accessible via methods like good() or fail() etc.) you can reset the stream using code similar to this:

    std::cin.clear(); 
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Saw this post yesterday: How I instantiate? Include code The user could not get
I saw the Qt source code like this: class Q_CORE_EXPORT QBasicAtomicInt { public: ...
Saw piece of code in book: T& operator[](int i) throw(RangeError) { if(i >= 0
I just saw something unusual behavior in Google Chrome's inbuilt spell check feature. This
I saw an unusual thing in This Website: AccuWeather.com Some tags in this page
Saw this in a book: Given: class SortOf { String name; int bal; String
Saw this piece of code in a Ruby on Rails book. This first one
I saw many threads with this tittle, but no one really speak about reuse
I saw some code when studying the open source project: here . But I
I saw the following fragment of C code in a text book and it's

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.