C++ loop program. (While, do- while, for, for each.

Hello everyone, I am new to the C++ programming language and was given an assignment to create a program that makes use of the while, do-while, for,and for-each loops. I know the basics but I'm finding it very difficult to understand loops. Please help, Here is the description of how the program should be:

Your program should present the user with the following options
* Option A: Your program must output the following sequence (the number of terms in
the sequence is given by the user): 1,5,7,17,31,65,127,257,511,1025, ...
* Option B: Your program must display all of the proper factors of a user provided
whole number (numbers which are wholly divisible by it).
* Option C: Your program must process a user-provided string by printing it in a zig-zag
pattern as follows (hint: consider using two strings, one for each line). For example
the string “Hello World!” will be printed as
H l o W r d
e l o l !
Hello. I am here just to give you hints:
1. The sequence is defined in this way:
5=2×1+3, 7=2×5-3, 17=2×7+3, 31=2×17-3 etc...
So we can see that general term is an=2×an-1±3, so you should make for loop, for(int n=1; n<=m-1; n++) where m is number of terms inputed by user and check if n is odd then the formula will be an=2×an-1+3, else if n is even then formula will be an=2×an-1-3. (Note that I don't count first term 1!, it should be printed before for loop!)
2. To print all divisors of integer you can make for loop again, for(int i=2; i<=n/2; i++) and check usung modulo operator if i divides n, and after that print 1 and n.
Last edited on
Topic archived. No new replies allowed.