Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Need help with 2D array problem
Author Message
Paul

Posted: Thu Apr 01, 2004 6:04 pm   Post subject: Need help with 2D array problem

Im suppose to make a program like the carnival ones, where you toss 10 coins onto a mat, the mat is numbered, so you get the same amount of points of the sum of the squares that the coins landed on, I can't seem to get the scoring right, I went to sleep at 3 am today lol, anyone help me find the problem? if you want to see how the squares are originally numbered more clearly, just look at the text file. Also if anyone has any suggestions as to how to make the check easier (other than restructuring my extra if statements), please post. oh yea X means the coin landed there once, Y means the coin landed there twice.

board.txt
Description:
Filename:  board.txt
Filesize:  76 Bytes

pennies.t
Description:
Filename:  pennies.t
Filesize:  2.03 KB

Delos

Posted: Thu Apr 01, 2004 7:18 pm   Post subject: (No subject)

Here's a way easier sol'n to it...

Have 2 2-dim arrays. One of them handles the scores...so, you'd put the text file stuff into that one.

The second one handles the scoring. You do the tossing of coins into that one.

Then, you do something like this:
- check coinArray (using a, b)
- if an X is found, then score := 1 * numArray (a, b)
- else if a Y is found, then score := 2 * numArray (a, b)
- display score.

Methinks your problem was that your checking was too lengthy and inefficient, thus you may have missed a couple of boxes.

Using 2 arrays means you can increase/decrease the size of the boards and still get everything you need!
Paul

Posted: Thu Apr 01, 2004 7:24 pm   Post subject: (No subject)

omg thank you thank you thank you, that was the most obvious way of checking it, yet I hadn't thought about it! damn some kind of brain block, but then Im so spaced out, its like Im typing and I dunno I was typing...
Paul

Posted: Thu Apr 01, 2004 7:45 pm   Post subject: (No subject)

Ok I just figured it out, there was nothing wrong with my previous really tedious checking code I just figured it out... thanx for helping me reduce 50 lines to 6 lines though, thanx alot. But it all came down to the right checking but wrong display,
this code
 code: for a : 1 .. 6         for b : 1 .. 6             if b = 1 then                 x := 195             end if             Font.Draw (board (a, b), x, y, font, black)             x += 67         end for         y -= 66     end for

goes after
 code: if board (px, py) = "X" then         board (px, py) := "Y"     end if     if board (px, py) not= "X" and board (px, py) not= "Y" then         board (px, py) := "X"     end if

this code, b4 that, they were switched, so the last X wouldn't get drawn, and I would think I got the freaking scoring wrong. God damn it I wish there was a way to stop making these damned stupid tiny mistakes that are so freaking time consuming.
Delos

Posted: Thu Apr 01, 2004 8:51 pm   Post subject: (No subject)

Oh, but there is!

It's called "not staying up until 3 am unless you're not going anywhere the next day (well, that day by then)"

 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 5 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: