English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

do{
cout << "Enter a value in the range of 5 to 10: " << endl;
cin >> num2;
if(num2 <= 5 && num2 >= 10)
cout << "This value is not in the proper range please try again" << endl;
}while(numValues2 > 1);


this is for an output that looks something like this

Enter a value in the range of 5 to 10: 4
This value is not in the proper range; please try again

Enter a value in the range of 5 to 10: 20
This value is not in the proper range; please try again

Enter a value in the range of 5 to 10: -6
This value is not in the proper range; please try again

Enter a value in the range of 5 to 10: 7



When I conpile and run this loop, it only goes through once. What seems to be the problem?

2007-03-26 14:19:59 · 3 answers · asked by jkim972 3 in Computers & Internet Programming & Design

3 answers

That code has some issues. Check your conditions. I can see you have a problem with the if condition.

if ( num2 <= 5 && num2 >=10 ) will never succeed...

you cant have a number 5 or less and 10 or greater at the same time!

2007-03-26 14:36:16 · answer #1 · answered by blue_10_T 2 · 1 0

if(num2 <= 5 && num2 >= 10)?

a value cannot be placed in this field. could you think of a number that would be less five and over 10?
try if(num2 <= 5 || num2 >= 10)

|| represent or statement.

2007-03-26 14:31:48 · answer #2 · answered by Oliver D4 1 · 0 0

I like this statement so much I am going to use it again.
I have never written a C++ program in my life.

There I feel so much better for that.

Your loop control compares a variable to 1.
}while(numValues2 > 1);

The variable numValues2 is not in your loop and so control for the loop is outside of the loop.

My guess is that numValues2 is set to zero so the loop will only be done once.

You already have the other corrections.

2007-03-26 20:06:01 · answer #3 · answered by AnalProgrammer 7 · 1 0

fedest.com, questions and answers