?
Solved

cin>>overflow

Posted on 1997-10-13
2
Medium Priority
?
352 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

765 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