Output only certain numbers of counter

I have been searching for hours and can't find help. Please help. I know it's gonna be some simple trick, but when you have no clue what that trick is, it might as well be brain surgery.

Here's the assignment:

"Write a counter-controlled program that counts from 1 to 100,

but only print to screen individual numbers listed:

1 thru 5,
11 thru 15,
20 thru 24,
30 thru 35,
46 thru 50,
60 thru 70,
80 thru 85 and
99 thru 100"



1
2
3
 for (int counter = 1; counter <= 100; counter++)

Is there an "if(counter btwn 1 and 5) cout counter" ????
.
Last edited on
 
Is there an "if(counter btwn 1 and 5) cout counter" ????

You can write an if statement that does just what you described.

Hint: Use a combination of Comparison operators (ex: < and <=) and Logical operators (ex: &&).
http://www.cplusplus.com/doc/tutorial/operators/#relational
http://www.cplusplus.com/doc/tutorial/operators/#logical

1
2
3
4
5
 
if ( /* checking code here */ )
{
    cout << counter << '\n';
}
Last edited on
Thank you SakurasouBusters for the offer and thank you EtDecius for the tutorial links. The "&&'s" did it!! I knew I was gonna feel sheepish for how easy it was. Thanks again.
Topic archived. No new replies allowed.