CodeBlocks compiler

I am running this code on a Codeblocks compiler and on an online compiler. The Codeblocks compiler goes in an infinite loop printing infinite "-----" while the online compiler runs it correctly. I am using the GNU GCC Compiler in CodeBlocks, I don't know to which compiler I should change it to or plugin to add to make the code run.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  #include <iostream>
#include <math.h>
#include <ctype.h>

using namespace std;
 int main(){

  float j;
    int n;
  while ( n%2 == 0)
  {
  cout<<"Enter a number:\n";
  cin>>n;
  }

    float a = ceil(n/2.0);

  for (float i = 1; i <= a ; i++)
  {
    for (j = 1; j <= i; j++)
    {
        cout << "*";
    }

    for (j = 2*(a - i) + 1; j >= i; j--)
    {
        cout << "-";
    }

    for (j = 1; j <= i; j++)
    {
        cout << "*";
    }


     cout << endl;
  }


  return 0;
}





Why don't you try initializing n to 0?
Topic archived. No new replies allowed.