Random printing

What this is supposed to do is find an x and y coordinate on the window and print a line of #'s in a random direction, with a random amount of #'s.

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <curses.h>
#include <iostream>

const int mamapy = 22;
const int mamapx = 80;
const int mahall = 7;
const int mihall = 1;
const int maroom = 9;
const int miroom = 5;

void gen_dungeon()
{
    srand(time(NULL));
    int y,x,d,l; // ycoord, xcoord, direction, length
    y = rand() % mamapy + 1;
    x = rand() % mamapx + 1;
    d = rand() % 4 + 1;
    l = rand() % (mahall - mihall + 1) - mihall;
    
    bool canmake = true;
    if(y < 0 || y >= mamapy || x < 0 || x >= mamapx)
    {
    canmake = false;
    }
    
    if(canmake)
    {
        switch (d)
        {
            case 1: // up
                for(int up = l; up > 0; up--)
                mvprintw(up,x,"#");
            break;
            case 2: // down
                for(int down = 0; down < l; down++)
                mvprintw(down,x,"#");
                break;
            case 3: // left
                for(int left = l; left > 0; left--)
                mvprintw(y,left,"#");
                break;
            case 4:
                for(int right = 0; right < l; right++)
                mvprintw(y,right,"#");
                break;
        }
    }
    else
    {
        printw("failure\n");
        if(y < 0)
        {
            printw("y > 0");
        }
        else if(y >= mamapy)
        {
            printw("y >= mamapy");
        }
        else if(x < 0)
        {
            printw("x < 0");
        }
        else if(x >= mamapx)
        {
            printw("x >= mamapx");
        }
        else
        {
        printw("unknown");
        }
    }
}


This works most of the time, but the rest of the time it gets to the else and tells me that x >= mamapx and what not. And then if it doesn't do that, nothing prints on the screen at all.

So I really have no idea why it's doing that. Can anybody explain?
Topic archived. No new replies allowed.