Variable Trouble

Well, I've got a variable that I want to store in part of a variable. I tried
to use the iostream <<#<< way, but it hasn't worked. This is my current progress in the file:

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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <allegro.h>
#include <cstdlib>
#include <time.h>
#include <iostream>

int die1num = 1;
int die2num = 1;
int die1draw;
int die2draw;
int timer = 1;
BITMAP* Image;
BITMAP* Die1;
BITMAP* Die2;
BITMAP* Die3;
BITMAP* Die4;
BITMAP* Die5;
BITMAP* Die6;

void endgame() {
     
     timer = 0;
     
     }

void diceroll() {
     
     die1num = rand() %6 + 1;
     die2num = rand() %6 + 1;
     die1draw = Die<<die1num<<;
     die2draw = Die<<die2num<<;
     timer = 1;
     
     acquire_screen();
     blit (die1draw, screen, 0, 0, 731, 450, 29, 29);
     blit (die2draw, screen, 0, 0, 700, 450, 29, 29);
     release_screen();
     
     }
                
int main() {
    
    allegro_init();
    install_keyboard();
    set_color_depth (16);
    set_gfx_mode (GFX_AUTODETECT, 920, 560, 0, 0);
    
    Image = load_bitmap ("Board.bmp", NULL);
    Die1 = load_bitmap ("Dice1.bmp", NULL);
    Die2 = load_bitmap ("Dice2.bmp", NULL);
    Die3 = load_bitmap ("Dice3.bmp", NULL);
    Die4 = load_bitmap ("Dice4.bmp", NULL);
    Die5 = load_bitmap ("Dice5.bmp", NULL);
    Die6 = load_bitmap ("Dice6.bmp", NULL);
    srand (time (NULL));
    
    acquire_screen();
    clear_to_color (screen, makecol (255, 255, 255));                  
    blit (Image, screen, 0, 0, 5, 20, 521, 521);
    blit (Die1, screen, 0, 0, 700, 450, 29, 29);
    blit (Die1, screen, 0, 0, 731, 450, 29, 29);
    release_screen();
    
    while (timer > 0) {
          
          clear_keybuf();
          readkey();
          if (key[KEY_ESC]) {
                            endgame();
                            break;
                            }
          else if (key[KEY_R]) {
                              diceroll();
                              }
          timer = 1;
          }
    
    destroy_bitmap (Image);
    destroy_bitmap (Die1);
    destroy_bitmap (Die2);
    destroy_bitmap (Die3);
    destroy_bitmap (Die4);
    destroy_bitmap (Die5);
    destroy_bitmap (Die6);
        
    return 0;
    
}

END_OF_MAIN();    


I guess if you were using Batch, you would enable delayed expansion and type
!Die%die1num%!, but i don't know how to do this for C++ Any help? Thank you in advance!
std::cout << "Die Bart, Die " << die1num << '\n';
This is Allegro, using graphics for the dice, and not text. I need a variable in a variable, and this won't work for my purposes. I need the variable for the random number to be part of the variable for the die image to show. This would just display text. You can see where I attempted already in void diceroll(), but the compiler just says that Die was not earlier defined as a variable. Can anyone help?
Sorry, now I get it.

http://cplusplus.com/doc/tutorial/arrays/
1
2
3
4
5
6
7
BITMAP* Die[6]; //an array (index goes from 0 to 5)
//loading
Die[2] = load_bitmap ("Dice3.bmp", NULL); //remember that start in 0

//choosing
BITMAP *die1draw = Die[rand() %6];
blit (die1draw, screen, 0, 0, 731, 450, 29, 29);



By the way, you should limit the scope of the variables.
No dice (no pun intended). I tried but the compiler says it's an illegal transition between BITMAP and Int, so it doesn't work, although it was a good idea that I managed to overlook. Thanks anyway. Any other suggestions?
It should work, ¿can you post the updated code?
I don't know, maybe it's because I used Allegro 4.1, and not 5, but that's because 5 wouldn'r download. When the compiler said it didn't work, I deleted it, but I did it pretty much exactly as you said, but it didn't work. The compiler reads 'Illegal transition between BITMAP and Int', and stops. Any other ideas?
Topic archived. No new replies allowed.