using arrays (urgent please)

closed account (9G3v5Di1)
Write a C++ program with the following specifications:
1.Use two-dimensional array with size 7 columns and 5 rows.
2.Seat numbers are populated during run-time.
3.User is asked to input a seat number.
4.Seat number chosen is replaced by 0.
5.Program displays a remark “Seat successfully reserved” when reservation is done.
6.User is not allowed to reserve a previously reserved seat. Display “Seat is taken” remarks.
7.User is not allowed to enter an invalid seat number. Display an error message.
8.Program continuously loops.

Sample Output:
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

Enter seat number to reserve : 11


1	2	3	4	5	6	7 
8	9	10	0	12	13	14
15	16	17	18	19	20	21
22	23	24	25	26	27	28
29	30	31	32	33	34	35

Enter seat number to reserve :


This is what I've done so far:

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
#include <string>
#include <iostream>
#include "_pause.h"

using namespace std;

int main() {
	int array[5][7] = {{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}};

	for(int row = 0; row < 5; row++){
		for(int column = 0; column < 7; column++){
			cout << array[row][column] << "\t";
		}
		cout << endl;
	}

	cout << endl;

	int seatNumber;
	cout << "Enter a seat number to reserve: ";
	cin >> seatNumber;

	std::cin.get();
	_pause();
	return 0;
}


Output:
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

Enter seat number to reserve :
Last edited on
Tip:
1
2
3
4
5
6
int seatNumber;
cout << "Enter a seat number to reserve: ";
cin >> seatNumber;

const int row = (seatNumber-1) / 7 ;
const int column = (seatNumber-1) % 7 ;

closed account (9G3v5Di1)
oh wow okay let me apply this
closed account (9G3v5Di1)
okay how do i change the value entered by the user to 0 and then printing the whole array as it is?

Sample Output:
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

Enter seat number to reserve : 11


1	2	3	4	5	6	7 
8	9	10	0	12	13	14
15	16	17	18	19	20	21
22	23	24	25	26	27	28
29	30	31	32	33	34	35

Enter seat number to reserve :


how do I loop this continuously? I'm almost there..
Last edited on
@goldwinbryanr,
Please stop double-posting your class exercises. Your other thread on the same problem is here:
http://www.cplusplus.com/forum/beginner/242863/#msg1077609

If you want to repeat something continuously then use a loop; either
1
2
3
4
for ( initialisation ; test ; increment )
{
   // code to be looped
}


or

1
2
3
4
while( condition to loop )    // test to run loop applied at the start of the loop
{
   // code to be looped
}


or

1
2
3
4
do     // test to run next loop applied at the end of the loop (so must loop at least once)
{
   // code to be looped
} while( condition to loop )


or, occasionally,

1
2
3
4
5
6
while ( true )
{
   // some code
   if ( condition to jump out of loop ) break;
   // some code
}



Fundamentally, it is up to YOU to decide:
- what code is to be repeated;
- why and when to stop looping
Last edited on
closed account (9G3v5Di1)
can you give me hint on how to change the entered value to 0?
goldwinbryanr wrote:
can you give me hint on how to change the entered value to 0?


array[row][column] = 0;
Last edited on
closed account (LTbpSL3A)
Hi,

Can you please give me a hint what do i put in condition to loop?

I already tried to put what do i need to repeat but it won't run.

I was confused of the order/sequence of the code, to run it successfully and continuously.

:(
Last edited on
Assuming you're trying to solve the same problem as the OP - the problem, as stated, does not specify any conditions that will end the loop. What conditions do you want to end the loop?
I already tried

Lets assume (like you do) that we are psychics and can see what you did. If so, then we can assume that you are psychic too and can read the answers from our minds.

Problem solved?


Thought so. Time for plan B:

Step 1: You show in detail what you have tried and what confusion you do have.
Step 2: We might be able to explain some of the details to you.
Step 3: Enlightenment.
closed account (LTbpSL3A)
I run this one,

#include <string>
#include <iostream>
#include "_pause.h"

using namespace std;

int main();
{
int array[5][7] = {{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}};

for(int row = 0; row < 5; row++)
{
for(int column = 0; column < 7; column++)
{
cout << array[row][column] << "\t";
}
cout << endl;
}

cout << endl;

int seatNumber;
cout << "Enter a seat number to reserve: ";
cin >> seatNumber;

std::cin.get();
_pause();
return 0;
}


and the output:


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

Enter seat number to reserve :
Last edited on
No, @jenifer, you simply copied that from
http://www.cplusplus.com/forum/beginner/243394/#msg1079138
Or was it simply what you were given in the first place?

If you make an effort then people may help you.

Consider:
- what section of code do you want to repeat/loop?
- what criterion do you have for continuing or stopping looping?
YOU have to decide this.
Last edited on
Two close accounts in the same thread?

Something doesn't smell right here...
Probably the first one was just careless ( http://www.cplusplus.com/forum/beginner/243420/#msg1079181 ) and he/she had contributed a bit to some interesting threads.

The second was, I think, either mischievous or a hanger-on.
Last edited on
Topic archived. No new replies allowed.