+ 1

How to set limit in while loop. Eg.while (20<num<30)?

#include <iostream> using namespace std; int main() { int num; cin>>num; while(10<num<20) { cout<<"number:"<<num<<endl; num++; } return 0; } I've tried this code but whenever I put any number output is showing unlimited numbers..?

1st Mar 2017, 5:54 PM
RAHUL PATIDAR
RAHUL PATIDAR - avatar
1 Odpowiedź
+ 6
You must use a composite boolean operation: instead of 10<num<20 try num>10 && num<20
1st Mar 2017, 5:55 PM
Álvaro