please am having a problem with my code below. am actually want is when a numebr lesser than 0 and greater than 99, it should output an error message till the correct value is entered for the three numbers. please would be very greatful if my code could be edited.. thanks

int _tmain(int argc, _TCHAR* argv[])

{
cout <<"\nweclome to c++\n";
cout <<"Enter three values in the range of 0 to 99.";

do
{

cout<<"\nvalue1: ";
cin >> nvalue1;

}
while (0 > nvalue1|| nvalue1 > 99); 


do
{


cout<<"\nvalue2: ";
cin>> nvalue2;

}
while (0 > nvalue2||nvalue2 > 99 );

do 
{

cout<<"\nvalue3: ";
cin>> nvalue3;

}
while (0 > nvalue3||nvalue3 > 99 );

Recommended Answers

All 7 Replies

when a numebr lesser than 0 and greater than 99

A number can never be smaller then 0 AND bigger then 99 at the same time.
What you mean is: (number < 0 || number > 99)

Yeah, it's true what niek_e said ...

You could make use of a function like this one:

int get_range(int a, int b)
{
	int c;
	do
	{
		if(c > a && c < b)
			return c;
		else
			cout << "Please enter a number between " << a << " and " << b << ": " << endl;
	} while (cin >> c);
}

Yeah, it's true what niek_e said ...

You could make use of a function like this one:

int get_range(int a, int b)
{
	int c;
	do
	{
		if(c > a && c < b)
			return c;
		else
			cout << "Please enter a number between " << a << " and " << b << ": " << endl;
	} while (cin >> c);
}

Awfully! You compare unitialized variable c...

A number can never be smaller then 0 AND bigger then 99 at the same time.
What you mean is: (number < 0 || number > 99)

It's exactly the same condition as (0 > number || number > 99 ;)

It's exactly the same condition as (0 > number || number > 99 ;)

You're right. I didn't really look through his/her code, because I was being a lazy b*stard :)

Awfully! You compare unitialized variable c...

Oh, that was a dumb mistake !

Change line 3 in the code I posted to int c = a; ...

thanks peeps i'll try data out, and get back too you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.