Exception Handling

So on the myprogramminglab there is a problem but i am stumped on

Basically it is an exception handling problem

Assume  the existence of a class  RangeException, with a constructor  that accepts minimum, maximum and violating integer  values  (in that order).

Write a function, void verify(int  min, int  max) that reads in integers  from the standard input and compares  them against its two parameters . As long as the numbers are between  min and max (inclusively), the function continues to read in values . If an input value  is encountered that is less than  min or greater than  max, the function throws a RangeException with the min and max values , and the violating (i.e. out of range) input.


so im assuming we start of with

void verify (int min, int max)
{

int input;
cin >> input;
if (input < min || input > max)
throw new RangeException (Min, Max)
}

Last edited on
anybody =o?
Try putting the if statement (and its throw statement) inside a while loop, with the condition being
cin >> input.
Last edited on
the only thing is see wrong is :

As long as the numbers are between min and max (inclusively), the function continues to read in values


based on this instruction, you should use a loop instead
so its suppose to be like this?
int input;
while (cin >> input)
{
void verify (int min, int max)
{
if (input < min || input > max)
throw new RangeException (min, max);
}
}
Last edited on
void verify (int min, int max)
{
int input;
while (cin >> input)
{
if (input < min || input > max)
{
throw RangeException (min, max,);
}
}
}
ah ok thank you everybody n.n
what was the final code
void verify (int min, int max)
{
int input;
while (cin >> input)
{
if (input < min || input > max)
{
throw RangeException (min, max, input);
}
}
}


that should do it
Topic archived. No new replies allowed.