| View previous topic :: View next topic |
| Author |
Message |
ElectroFusion Grandmaster Cheater
Reputation: 0
Joined: 17 Dec 2006 Posts: 786
|
Posted: Sun Nov 09, 2008 8:28 pm Post subject: [C++] an array |
|
|
I was making a script in c++ and thought
could I do a while event for an array
the array being like so [not sure how arrays work in c++]
array NUMBERS;
array NUMBERS = Array("1, 2, 3, 4, 5, 6, 7, 8, 9, 10");
and then have a while event where it repeats until it finishes, but using the number out of the array.
Basically
while(NUMBERS < 10){
PostMessageA("NUMBERS");
}
I know this code wouldn't work in a million years, but just as an example.
So it would keep saying a number until finished.
"1" "2" "3" "4" "5" "6" "7" "8" "9" "10"
Thanks a ton _________________
| qwerty147 wrote: |
| ghostonline wrote: |
what world are you in?
|
bera
but i live in NZ
|
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sun Nov 09, 2008 8:44 pm Post subject: |
|
|
first off thats not how you define an array, learn the context.
and array is defined like
type var [sizeofarray];
so say an int array of 10
int varname[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
now thats not how you wanna go about it anyways
| Code: |
int var = 0;
while (var < 10)
{
printf("Value: %d", var);
var++;
} |
_________________
|
|
| Back to top |
|
 |
ElectroFusion Grandmaster Cheater
Reputation: 0
Joined: 17 Dec 2006 Posts: 786
|
Posted: Sun Nov 09, 2008 9:04 pm Post subject: |
|
|
thanks. Another question, how would I make it do the array itself?
Like I tell it 3 and 100 and it automatically makes the array which numbers 3-100
nvm figured it out _________________
| qwerty147 wrote: |
| ghostonline wrote: |
what world are you in?
|
bera
but i live in NZ
|
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sun Nov 09, 2008 9:09 pm Post subject: |
|
|
| Code: |
int max, min;
printf(" Enter your min and max: ");
scanf("%d", min);
scanf("%d", max);
int val[max];
int i=0;
while( i < max );
{
val[i] = min+i;
i++;
}
|
i think that should work.
didn't test it. but go for it _________________
|
|
| Back to top |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Sun Nov 09, 2008 9:45 pm Post subject: |
|
|
| I would think that the for-loop would be better for this (pun intended). |
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sun Nov 09, 2008 9:54 pm Post subject: |
|
|
yea, but i didn't feel like doing one  _________________
|
|
| Back to top |
|
 |
ElectroFusion Grandmaster Cheater
Reputation: 0
Joined: 17 Dec 2006 Posts: 786
|
Posted: Sun Nov 09, 2008 10:49 pm Post subject: |
|
|
Well how would i make it start at 0000 and go up
so each number would be like
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
EDIT: nevermind, tried to do a function like
if (var < 10){
var = 000 + var;
}
and so on and so forth. harder way, but you gotta do what you gotta do amirite? _________________
| qwerty147 wrote: |
| ghostonline wrote: |
what world are you in?
|
bera
but i live in NZ
|
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Mon Nov 10, 2008 9:11 am Post subject: |
|
|
| ElectroFusion wrote: | Well how would i make it start at 0000 and go up
so each number would be like |
| Code: | int i;
for(i=min; i<=max; ++i)
printf("%04d\n", i); | :D Anyway, the numbers are always stored with preceding zeroes, assuming that there's enough space in the variable. It's all about printing. |
|
| Back to top |
|
 |
|