I have an AlphaSeats [60] array and the loop I did, changes the value to 0 and it's suppose to stop when it reaches the index 59 but it goes on and end up changing other variables - PartyName, PartySize and Airplane value to 0 too...

Here is the code. I could not figure out why this is happening...

Anybody who can help me I really appreciate

``````void main ()

{
char    PartyName[20][50];
int     PartySize[20];
int     Airplane[2];
int     AlphaSeats[60];
int     CountAlphaSpace(0);
int     BravoSeats[60];
int     CountBravoSpace(0);
int     i(0);
int     j(0);

cout << "Please, ente the Party Name: ";
cin >> PartyName[i];
cout << "\n";

cout << "Please, ente the Party Size: ";
cin >> PartySize[i];
cout << "\n";

cout << "Please, choose an Airplane: 1- Alpha or 2- Bravo: ";
cin >> Airplane[i];

for (j = 0; AlphaSeats [j] <= 59; j++)
AlphaSeats[j] = 0;

for (j = 0; BravoSeats [j <= 59]; j++)
BravoSeats[j] = 0;

if (Airplane[j] == 1) //Alpha plane
{
do
{
if (AlphaSeats[j] < 0)
CountAlphaSpace++;
else;
j++;
}while(AlphaSeats[j < 60]);
}
else;
{
do
{
if (BravoSeats[j] < 0)
CountBravoSpace++;
else;
j++;
}while(BravoSeats[j < 60]);
}

}``````
3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Reprise

Before I help can you explain what your trying to achieve here:

``````for (j = 0; AlphaSeats [j] <= 59; j++)
AlphaSeats[j] = 0;

for (j = 0; BravoSeats [j <= 59]; j++)
BravoSeats[j] = 0;``````

Before I help can you explain what your trying to achieve here:

``````for (j = 0; AlphaSeats [j] <= 59; j++)
AlphaSeats[j] = 0;

for (j = 0; BravoSeats [j <= 59]; j++)
BravoSeats[j] = 0;``````

I just fixed that:

What I wanted to do is to add 0 to all 60 indexes.

``````for (j = 0; j <= 59; j++)
AlphaSeats[j] = 0;

for (j = 0; j <= 59; j++)
BravoSeats[j] = 0;``````

[/

Is there any other problem?

After you fixed your "for" loop I don't see a problem... other than in C++ the main function needs to have an integer return type.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.