[Dev-C++] Newbie: setting vars with for loop trouble.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Dane E. <DE...@pa...> - 2004-06-17 20:17:06
|
Hi all,
Thanks in advance for any help you can offer me.
=20
I have a newbie question. I need to roll six dice using a rollDice();
function
In the function I need to use a for loop to increment through my six
dice variables that I set as global variables as:
die1, ..., die6. I cant figure out how to append the value of my
for-loop variable to the name of my "die" variable, so I can set it?=20
Is there a better way to do this? Im not supposed to use an array for
this assignment, but I am supposed to use=20
a loop. Here is what I have done so far:
=20
int die1, die2, die3, die4, die5, die6; //global variables
=20
//my broken function so far
void rollDice()
{
int i;
for( i =3D 1; i =3D 6; i++)
{
"die"+i =3D i; // I know this is wrong, but I wrote it this way =
to
illustrate my problem. ;-)
}
}
|