473,322 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

array Loop, help please !

5
Hi there,

I’m working on a freeCell homework, there are 8 piles in the tableau (which is an array of Pile objects), and i need go through a loop, and take a card from the deck , and put it into the current tableau pile, then step to the next tableau pile, and back to the first one when it reach 8th tableau pile.

This is my code:
Expand|Select|Wrap|Line Numbers
  1.         newDeck = new Deck(seed);
  2.         while (!(newDeck.numCardsRemaining() == 0)) {
  3.             for (int i = 0; i < 8; i++) {
  4.                 tableau[i].put(newDeck.nextCard()); 
  5.                 i = (i + 1) % 8;
  6.             }
  7.         }
.
.
.
.
Expand|Select|Wrap|Line Numbers
  1.         for(int i=0;i<8;i++){
  2.             int s = i+8;
  3.             System.out.println(s + ":" + " " + tableau[i].toString());
  4.             s++;
  5.         }
This gives me:

Tableau:
8: [DK,H7,D7,HQ,C3,HK,D5,C5,SA,S10,C6,S5,C8]
9: []
10: [D10,S3,S7,D3,H8,H6,C2,CA,CQ,C4,H4,C10,D8]
11: []
12: [SJ,D2,CJ,S9,S2,D4,S4,H9,SK,D9,HA,H3,HJ]
13: []
14: [C7,H5,CK,SQ,H2,D6,C9,DQ,H10,S8,S6,DA,DJ]
15: []

But it should be:

Tableau:
8: [DK,D7,C3,D5,SA,C6,C8]
9: [D10,S7,H8,C2,CQ,H4,D8]
10: [SJ,CJ,S2,S4,SK,HA,HJ]
11: [C7,CK,H2,C9,H10,S6,DJ]
12: [H7,HQ,HK,C5,S10,S5]
13: [S3,D3,H6,CA,C4,C10]
14: [D2,S9,D4,H9,D9,H3]
15: [H5,SQ,D6,DQ,S8,DA]


Any Help will be much appreciated.
Thanks!
Sep 24 '06 #1
1 1359
Limpor
5
Never mind i figrued it out now.
Sep 25 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mark A Framness | last post by:
Greetings, I am working on a project and we need to write a conversion script to initialize a new field on a table. The number of records on this table is on the order of millions so routine...
11
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I've noticed a few threads (full of sound and fury, signifying nothing) here recently about allocation of large memory blocks. I'm about to start on a personal pet project where I'll be using...
32
by: Joe Rattz | last post by:
Hmmm, I wrote the following code. I want an array of bools and I want to intialize them to false. bool bits = new bool; foreach(bool bit in bits) { bit = false; } The compiler complains...
1
by: Sluggoman | last post by:
Hi all, Am floundering through a course in which C was not a pre-req, but the assignment is in C - If someone could point out where I am going way off the rails, I'd apprecciate it. Please be...
5
by: Galahad | last post by:
I am using the code below to create a integer array. while(dr.Read()) { string StateID=dr.ToString(); int FacilityID=Convert.ToInt32(dr.ToString()); int FacilityIDs={FacilityID}; } ...
44
by: svata | last post by:
Hello, I wonder how to resize such array of structures using realloc()? #include <stdio.h> #include <stdlib.h> #define FIRST 7 typedef struct { char *name;
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
4
by: mab464 | last post by:
I have this code on my WAMP server running on my XP machine if ( isset( $_POST ) ) { for($i=0; $i<count($_POST);$i++) { if ($ans != NULL ) $ans .= ", " . $_POST ; // Not the first...
6
by: fjm | last post by:
I have this multidimensional array that I was given but do not understand it. What I was attempting to do with these arrays was to build them and then replace the values inside the cells. Here is...
2
by: jac130 | last post by:
I have an array, populated with student grades. there is a list of student names, but their grades are stored in a class level array. there is a calculate average button,that is supposed to calculate...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.