Solved

cin>>overflow

Posted on 1997-10-13
2
346 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
2 Comments
 
LVL 3

Accepted Solution

by:
eugenem earned 100 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

759 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now