This cout statement is causing my program to fail!

Could someone explain why this single cout << endl; statement is breaking my code? I cannot for the life of me figure out what is wrong. If I rem out the cout the code works, if i leave it netbeans says there is no exe file to open.

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
48
49
50
  
#include <iostream>
#include <iomanip>
using namespace std;

// This function prints a box of size x size/2 '*'s
void box(int size) {
    int a;
    int b = size;
    int d;
    int e;
    int f;
    int g;
   
    for (a=0; a<size; a++){
        cout << "*";
    }
    cout << endl;
    
    if (b%2 != 0)
        b = (b-1)/2;
    else 
        b = b/2;
    
    b = b - 2;
    
    g = size - 2;
    
    for (d=0; d<b; d++){
        cout << "*";
        for (e=0; e<g; e++)
            cout << " ";
        cout << "*" << endl;
    }
    for (f=0; f<size; f++){
        cout << "*";
    }
    cout << endl; // <-------WHY IS THIS RUINING MY CODE?
}
int main() {
  int i;
  int input;
  for (i = 0; i < 3; i++) {
    cout << "Enter box size: ";
    cin >> input;
    box(input);
  }
  cout << "The end." << endl;
}
This runs OK for me through the compiler linked on the forum (the little gear icon at the top right of the code box.) Could you have the code open unsaved while your trying to run the program? I'm sorry I'm not familiar with how projects are set up in netbeans.
Last edited on
Just ran it on Xcode and can confirm it runs fine.

I haven't used Netbeans in a while, but make sure that it's configured properly to run a program instead of doing something else like test it or something.
Topic archived. No new replies allowed.