attempt 2

This is a discussion on attempt 2 within the C++ Programming forums, part of the General Programming Boards category; heres my delimma: i made a program to print a map somewhat like this: [][] (exept 10X10) each square would ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    25

    attempt 2

    heres my delimma: i made a program to print a map somewhat like this: [][] (exept 10X10) each square would changes
    [][] depending on what number each "square" eaquals so if b[0][0]==0; then the square would be []. hence i used nested loops to make all b[x][y]=0; and so on. its supposed to be kind of like chess,a dn i have the "enemy program" down, but why isnt this code working?
    Code:
    #include <iostream>
    using namespace std;
    int main(){
    int b[9][9];
    int x, y, ex, ey, ax, ay, turncount;
    
    
    do{
    for(ay=0;ay<9;ay++){
    for(ax=0;ax<9;ax++){
    b[ax][ay]=0;
    }
    }
    if(turncount>0){
    b[x][y]=1;
    }
    b[2][2]=2;
    for(y=0;y<9;y++){
    for(x=0;x<9;x++){
    if(b[x][y]==0){
    cout<<"[]";
    }
    if(b[x][y]==1){
    cout<<"*•";
    }
    if(b[x][y]==2){
    cout<<"τζ";
    }
    }
    cout<<"\n";
    }
    for(;x>9 || y>9;){
    cin>>x>>y;
    turncount++;
    }
    cin.get();
    }
    while(0<1);
    cin.get();
    }

  2. #2
    *this
    Join Date
    Mar 2005
    Posts
    498
    I'll look at it, but btw that code is hard to read, you need to learn how to use spaces buddy and the tab button.

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    22
    Yes this code is hard to read.
    First thing that really sticks out here is that the do-while loop uses (0<1) as a condition which is always true. Since you don't have any break exit or return statements inside this loop it will run forever.

  4. #4
    *this
    Join Date
    Mar 2005
    Posts
    498
    you might as well replace this
    Code:
    for(;x>9 || y>9;)
    with a while statement
    Code:
    while (x>9 || y>9)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked lists; My first attempt
    By relyt_123 in forum C++ Programming
    Replies: 9
    Last Post: 11-05-2007, 01:54 PM
  2. Problem with my first linked list attempt.
    By SlyMaelstrom in forum C++ Programming
    Replies: 3
    Last Post: 11-09-2005, 03:33 AM
  3. Naming folders after the date - my futile attempt
    By shoobsie in forum C++ Programming
    Replies: 2
    Last Post: 06-24-2005, 09:50 AM
  4. Sigmaze! -- Second Attempt.
    By quzah in forum Contests Board
    Replies: 42
    Last Post: 11-09-2004, 05:45 PM
  5. *NOOB* attempt to make a calc prog
    By Inferno in forum C Programming
    Replies: 3
    Last Post: 08-30-2004, 10:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21