Codeblocks Help!

Does anyone know how to write this:

Generate the odd numbers from 15 to 53 (inclusive)? In a FOR loop as well. I have no idea how to make this program.

I tried at it, with while as well. But in the output it just kept repeating 15 in an infinite loop. Can anyone change this to for and fix it so it works? and tell me what I did wrong? Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
      int Number;


  cout << " number\t\n" << endl;

 Number = 15;
  while (Number<=53)


          cout << Number << "\t" <<endl;
        Number = Number + 3;
    return 0;


}
Last edited on
What's the distance from one odd number to the next odd number? (Hint: it's not 3)
Also if you want multiple statements within a loop, you need to enclose them in braces. Right now, only the first statement printing out the number is looping. It never gets to the incrementing statement.

1
2
3
4
5
	while (Number<=53)
	{ // add opening brace to have multiple statements in while loop
		cout << Number << "\t" <<endl;
		Number = Number + 2;
	} // end while loop brace 



1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;

int main()
{
    
    for (int i=15; i<=53; i+=2)
    	cout << i << "\t" << endl;
    
    return 0;
}
Last edited on
Topic archived. No new replies allowed.