Loops assignment

Can someone help me with this C++ programming. I use linux through putty to do this.

Create a C++ program which outputs the first four powers of three and then counts down by three. The output should look like this:


Counting up by powers of three...

1

3

9

27

Counting down by threes...

27

24

21

18

15

12

9

6

3

0

Done!
Let's say that n is the variable that holds the number to display. The trick here is that in the first loop, n is not the index of the loop. It's some other variable like i. Each time through the loop you multiple n by 3 and print it out.
Hello Masbah97,

In addition to http://www.cplusplus.com/forum/unices/204300/#msg974514 I would suggest the first for loop should work something like this: for (int i = n; i < 27; i*= 3). This way the for loop can use different numbers to generate the same concept.

Hope that help,

Andy
Topic archived. No new replies allowed.