[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

cin>>overflow

Posted on 1997-10-13
2
Medium Priority
?
353 Views
Last Modified: 2006-11-17
int Getvalue(double& d)
{

 //Flush clears the input buffer and resets error flags
 //Max and Mix resp 1-999
//Question how do i prevent an overflow
//eg.
//assign d 99999999999999999999999999999999999999999
//get an execption error?

inline void  Flush(istream& str)
{
      str.clear();
      int  char_to_skip =
            str.rdbuf()->in_avail();
   
       str.ignore(char_to_skip);
}

 Flush(cin);
 while(!(cin>>d).gcount()<4){

         if(!cin||d<Min||d>Max)
            cout<<endl<<"Invalid input!"<<endl<<"ReEnter Value: ";
    else break;

       Flush(cin);
     if(cin.eof())
        return 0;
 }
 return(1);
}
0
Comment
Question by:sigjas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
eugenem earned 400 total points
ID: 1171231
Read from cin not to a double but to string. Than convert this string to double (on this step you can perform any checks).
0
 

Author Comment

by:sigjas
ID: 1171232
Thank you
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question