Hi, thanks for taking your time to read and maybe drop some knowledge -
Im making a console application that lets you order tickets for seats in the cinema.
I've been trying to make a 2d array to use for the seats, using 15 rows and 20 seats.
I can't make it work proberly and im wondering what's the better way to build this project -
here's some things i tried:
int[ , ] pladser = new int[15, 20];
for (int foo = 0; foo < pladser.GetLength(0); foo++ ) { for (int bar = 0; bar < pladser.GetLength(1); bar++){ pladser[foo, bar] = 1 + bar;
Console.Write(pladser[foo, bar]);
//when i write it this way the console dose not change row after last seat but writes all the 20 seats through 15 in a single line
int[,] pladser = new int[,]
{
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
};
int foo;
foo = Convert.ToInt32(pladser);
Console.WriteLine(foo);
//this gives me no error reports but wont write it proberly due to a system 32 message -
int[,] pladser = new int[,]
{
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20},
};
for (int x = 0; x < 15; x = x++)
{
for (int y = 0; y < 20; y = y++)
{
}
Console.Write(pladser[x, y]);
//this time i thought i finally had it but i got something wrong still and cant run the program.
//the name y does not exist - probably just an easy fix?
// Any ideas how i could get this project going would be much appreciated
Loading
VulpesPosted Nov 11, 2013, 6:25 PM
At the moment, if the user doesn't want to choose the seats individually, the seats are chosen completely at random as it's much more complicated to choose adjacent seats, particularly as the cinema fills up, though something like this can certainly be coded.
Also there's not much in the way of error checking as there's a lot of stuff that could potentially go wrong:
VulpesPosted Nov 18, 2013, 11:13 AM
Different people learn new stuff in different ways. Personally, I've always preferred books to online videos as you can learn at your own pace without having to stare at the screen for long periods of time.
There are many good books on learning C# programming including this one which is particularly good if you're wishing to concentrate on the language itself rather than its myriad applications:
http://www.amazon.co.uk/C-4-0-The-Complete-Reference/dp/007174116X/ref=pd_sim_sbs_b_2
cSharpDonkeyPosted Nov 15, 2013, 7:43 PM
Also i wanna ask, what's a good way to get better at this, any advice?, tryed watching alot youtube guide's and read c# articles and books, any excercises or reading / video material you can recommend?
cSharpDonkeyPosted Nov 11, 2013, 6:58 PM
sincerely: c#Donkey
cSharpDonkeyPosted Nov 11, 2013, 4:32 PM
- Is it possible to a function to the Seat picking phase that lets user choose wether he/she wants to pick their own seats, or declare number of seats and then use Random to pick the number of seats anywhere currently available?(maybe even any X seats NEXT to eachother available)
and then add a function that lets the user say how many childs/adults for different prices -
so that the final price for all the tickets shows as the seats are reserved and turned red-
- please bare with me im eager to learn and get this working
VulpesPosted Nov 11, 2013, 4:18 PM
If you want the seats to be re-displayed after each seat is reserved - rather than when all the reservations have been made - then just move the final DisplaySeats() so that it's the last line in the for statement.
cSharpDonkeyPosted Nov 11, 2013, 4:01 PM
- can i do it vise versa so the user can get a look at which seets are free and which are avaible first?
or maybe so the input / output user vs program happens below the array so u can watch seats while you are using it?
VulpesPosted Nov 11, 2013, 3:51 PM
Try the highlighted code:
cSharpDonkeyPosted Nov 11, 2013, 12:14 PM
Hi Vulpes, this idea sounds very viable and logical.
my problem is i don't know how to get it started, and i'm having a hard time navigating through this foreign language of c#..
i have gone with your new way to build the program, i see what you are saying that its better to build it this way, i think i understand the theory behind this, but not in practise.
next step for me is to let the user choose a number of specific seats to reserve them, and color them red - rather then the preset 3 red seats you made for an example -
how can i pull this info from user to program, and use it ?
here is something i tried, i just wanted to try and write something and im aware this code wont work or run, but i hope you see my idea here
VulpesPosted Nov 11, 2013, 10:32 AM
I'd also move the code to show the seats (including the appropriate colors) to a separate method as you'll need to call it each time a seat is chosen or 'unchosen'.
The code will now look something like this:
cSharpDonkeyPosted Nov 11, 2013, 9:58 AM
Thanks - jaganatha and vulpes, my program is now runnable, and i've added the spaces in between items in the array thanks to your replie vulpes -
Here is when it gets tricky, i now wanna add a green background color to my seats if they are available, and red when they get chosen in program, how should i start doing this?.
I Believe im looking for some if / else statements? - any better ideas?
any critism, ideas, or general thoughts much appreciated !
VulpesPosted Nov 11, 2013, 9:49 AM
The output is:
cSharpDonkeyPosted Nov 11, 2013, 9:09 AM
for some reason thought, it writes 15x15 seats not the 15x20 intended
Jaganathan BantheswaranPosted Nov 11, 2013, 3:25 AM
for (int foo = 0; foo < pladser.GetLength(0); foo++ )
{
for (int bar = 0; bar < pladser.GetLength(1); bar++)
{
Console.Write(pladser[foo, bar]);
}
Console.WriteLine();
}