Need Help guys. (Arrays)

Hi,
my program is kinda seating arrangement system,
it works like when i enter a seat number, the program will change the value of that array from 0 to 1. Depending on the seat number if i enter 2 it should fill only 2 cell. (and its working like that.)
1
2
3
4
  Row 1   1 1 0 0 0 0 0
  Row 2   0 0 0 0 0 0 0
  .
  .

what i want is if the cells of this array already have 1 value stored then the program should skip those cells and fill the cells those have 0 value,
for E.g:
if enter 2 it is showing
1
2
3
4
  Row 1   1 1 0 0 0 0 0
  Row 2   0 0 0 0 0 0 0
  .
  .

and if program ask again to enter seats.. and user press 3, so it should skip those cells in which value if 1 and fill other 3 cells those have 0 values.
output should be like this:

(this is what i actually wants)

1
2
3
4
  Row 1   1 1 1 1 1 0 0
  Row 2   0 0 0 0 0 0 0
  .
  .


but instead its working like this :(
1
2
3
4
  Row 1   1 1 1 0 0 0 0
  Row 2   0 0 0 0 0 0 0
  .
  .

which is wrong :\

here is the full code.

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
#include<iostream>
#include <cstdlib> 
using namespace std;

double seats(int (*air)[7], int b, double price)
{
	cout<<"\n\nEnter seats: ";
	cin>>b;
	if(b<=14)
	{
	for (int i=0; i<2; i++)
{
		for (int j=0; j<b; j++)
		{
		
		if(air[i][j]==0)
		{
			air[i][j]=1;
		}
	}break;
}
	for (int h=0; h<12; h++)
	{
	cout<<"Row "<<h+1<<"\t";
	for (int k=0; k<7; k++)
	cout<<air[h][k]<<"\t";
	cout<<endl;
	}
	return 0;
}
else
cout<<"\nwrong input"<<endl;
}


int main ()
{
	int Ace;
	int b; 
	double price;
	int a[12][7];
	for (int i=0; i<12; i++)
	{
	for (int j=0; j<7; j++)
		a[i][j]=0;
	}
	do
	{
	cout<<"\n\n******************************";
	cout<<"\nPress 1 to Book Seats : ";
	cin>>Ace;
	cout<<"\n";
	switch(Ace)
	{
		case 1:
			{
				system("CLS");
				seats( a, b, price);
			}break;

	}
}while(Ace!=2);
cout<<"\n\nThank you For visiting....!!";
}
Last edited on
You can accomplish this by modifying the for loop on line 13
for(int j=0; j<7 && b>0; j++)
What this is saying is two conditions must be true for the for loop to continue.
Also inside the if statement where you set air[i][j] = 1; add b--;
The break statement on line 20 looks like an error to me.
Many Thank bro . u solved it.
Thanks again.
Topic archived. No new replies allowed.