#include <iostream>
#include <stdlib.h>
using namespace std;
struct TSprite
{
int x, y;
}Sprite;
TSprite Bullet[10];
int main(int argc, char *argv[])
{
for (int Loop =1; Loop< 10; Loop++)
{
Bullet[Loop].x;
Bullet[Loop].y;
cout << Bullet[Loop].x <<"\n";
}
system("PAUSE");
return 0;
}
help with c++ looop
You didn't actually do anything to Bullet[Loop].x or Bullet[Loop].y, you just increment Loop. So change these two lines (which do nothing):
Bullet[Loop].x;
Bullet[Loop].y;
To:
Bullet[Loop].x++;
Bullet[Loop].y++;
Bullet[Loop].x;
Bullet[Loop].y;
To:
Bullet[Loop].x++;
Bullet[Loop].y++;
Quote:Original post by baddogjhow can you not be sure about that?
One thing is, im pretty sure loop should start at 0, not 1. I may be wrong.
indexing starts at 0
Quote: Bullet[Loop].x;
Bullet[Loop].y;
These statements do nothing; there is no assignment taking place. You need to change their values:
Quote: Bullet[Loop].x += 1;
Bullet[Loop].y += 1;
Or:
Quote: Bullet[Loop].x++;
Bullet[Loop].y++;
or any of a number of other similar variants.
if Bullet[Loop].x++;
output
1
1
1
1
1
1
1
1
1
if Bullet[Loop].x;
0
0
0
0
0
0
0
0
0
but what I need is Bullet[Loop].x
to have [Loop] to increse by 1
so what I want displayed is
1
2
3
4
5
6
7
8
9
But I cant figure out how to do that.
output
1
1
1
1
1
1
1
1
1
if Bullet[Loop].x;
0
0
0
0
0
0
0
0
0
but what I need is Bullet[Loop].x
to have [Loop] to increse by 1
so what I want displayed is
1
2
3
4
5
6
7
8
9
But I cant figure out how to do that.
The simple answer is: you increment each item in the array, and then print out that item. If they start at 0, you will always get 1.
If you want to do what you're saying:
If you want to do what you're saying:
for(int loop = 0; loop < 10; ++loop) { Bullet[Loop].x = loop; std::cout<<Bullet[Loop].x<<std::endl;}
for(int i = 0; i < 10; ++i){ for(int Loop = 0; Loop < 10; ++Loop) { ++(Bullets[Loop].x); ++(Bullets[Loop].y); cout << "bullet: " << Loop << " x: " << Bullets[Loop].x; cout << "\n\t y: " << Bullets[Loop].y << endl; }}
Why don't we just assign the value of the bullet array counter to the x and y coordinates? Because we want to enable various limits (you could go up to a limit of 20, or 30, or 100).
Wow now that just made my brain hurt.
so now I dont know what I need to do.
Let see if I can explain it better.
Bullet[Loop].x;
I need Bullet[Loop].x to really look like this
Bullet[1].x;
Bullet[2].x;
Bullet[3].x;
Bullet[4].x;
ect
then I will change Bullet[Loop].x; to = Bullet[Loop].x = player.x; at the start then it needs to increse by itself and then when I make another one it needs to start at player.x but take on its own postion.
so now I dont know what I need to do.
Let see if I can explain it better.
Bullet[Loop].x;
I need Bullet[Loop].x to really look like this
Bullet[1].x;
Bullet[2].x;
Bullet[3].x;
Bullet[4].x;
ect
then I will change Bullet[Loop].x; to = Bullet[Loop].x = player.x; at the start then it needs to increse by itself and then when I make another one it needs to start at player.x but take on its own postion.
Quote:Original post by capn_midnightQuote:Original post by baddogjhow can you not be sure about that?
One thing is, im pretty sure loop should start at 0, not 1. I may be wrong.
indexing starts at 0
I'm positive it starts at 0, but i didn't want to risk get fired at for somehow giving falso information
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement