Create a new file with the following code in main():

a for loop that prints the numbers 75 to 125
a for loop that prints the numbers 50 to 30, in reverse order

a while loop that prints the numbers from 66 to 111
a while loop that prints the numbers from 50 to 30, in reverse order

a for loop that prints any number from 1 to 100 that:
--- is evenly divisible by 3 or is evenly divisible by 4
(example: 3,4,6,8,9,12...)

Recommended Answers

All 2 Replies

I could, but if you don't even know how to start then you know nothing about loops. That means you are either skipping class or sleeping during. Reread your notes or look up the syntax of C++ loops. I think there is a thing called Google that might be of help.

I should point out that technically

a for loop that prints the numbers 50 to 30, in reverse order

Might not be what you think. The numbers from 50 to 30 would be

50 49 48 ... 31 30

The numbers from 50 to 30 in reverse order then would actually be

30 31 32 ... 49 50

Best to clarify that question. As someone learning (or I hope you are learning) to program, one of the most important lessons is to get clarification on any spec that is ambiguous. Clear communication is key. As a long-time married person I am only too aware that two people can hear the same sentence and understand it to mean two different things. To wit - if today is Tuesday and someone says "see you next Saturday", do they mean in four days (this Saturday) or in 11 days?

Typically, the best way to start is with pseudocode and you pretty much have that just from what you've posted, with the exception of clarifying what is meant as was mentioned above.

From that pseudocode, start by adding in the logic to do just what is being asked; meaning increment by 1 for 75 - 125, decrement by 1 for 50 to 30 (if that's what is actually called for), etc. It's easiest to implement most things when you break them down to the simplest case instead of staring at the entire thing (blinded by the forest when looking for a tree).

As for the numbers that are divisible by 3, or 4, many ways to do it, but using modulo can check to see if some number divided by another is equivalent to 0 will do: N % (3 or 4) == 0. The rest of the logic should be fairly straightforward from there.

The best way to get more detailed answers, or help, is to actually post your own attempts to solve the problem at hand, along with the errors you're receiving. Otherwise, you'll get very generic answers as no one is going to do the work for you. In fact, what I've just posted is probbably more detail that some would ever give for such a question.

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.