Placing Battleships PSPAD C++
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Placing Battleships PSPAD C++

  1. #1
    Join Date
    Mar 2013
    Posts
    4

    Placing Battleships PSPAD C++

    I'm trying to place battleships in my battleship board which I've already created using a sub routine. I'm trying to create another sub routine to do this... so far this is what I have.

    When I enter in the coordinates it just keeps giving me back the same ship, It wont let me move onto the next one... What am I doing wrong?

    # include <stdio.h>
    # include <stdlib.h>

    void get_imput(player)
    char player;
    {
    int i,j;
    char H;
    char V;
    char o;

    do{
    printf("Shots fired! Commander, it's time for battle!\n");
    printf("Enter the coordinates of your carrier #,# and its orientation (H or V).\nMake sure these coordinates are between 1-10\n");
    printf("ex. 2 3 H\n");
    scanf("%d %d %c",&i,&j,&o);
    }
    while ( i < 10 && j < 10 && i > 0 && j > 0 && (o != 'H' || o != 'V'));

    printf("Enter the coordinates of your battleship in the same format\n");
    scanf("%d %d %d",&i,&j,&o);

    while( i < 10 && j < 10 && i > 0 && j > 0 && (o != 'H' || o != 'V'));

    printf("Enter the coordinates of your destroyer in the same format\n");
    scanf("%d,%d %d",&i,&j,&o);

    while( i < 10 && j < 10 && i > 0 && j > 0 && (o != 'H' || o != 'V'));

    printf("Enter the coordinates of your submarine in the same format\n");
    scanf("Deploy ship here %d,%d %d",&i,&j,&o);

    while( i < 10 && j < 10 && i > 0 && j > 0 && (o != 'H' || o != 'V'));

    printf("Enter the coordinates of your submarine in the same format\n");
    scanf("Deploy ship here %d,%d %d",&i,&j,&o);

    while( i < 10 && j < 10 && i > 0 && j > 0 && (o != 'H' || o != 'V'));
    }

    /*----------------------------------------------------------------------------
    ------------------------------------------------------------------------------*/
    void print_board(board)
    char board [10][10];
    {
    int i,j;
    int a=1;
    int c=1;

    for (a=0;a<11;a++){
    printf( "%4d",a);}
    printf("\n");
    printf(" +---+---+---+---+---+---+---+---+---+---+\n\n");

    for (i=0;i<10;i++){
    for(j=0;j<10;j++){
    board[i][j]= '|';}}

    for(i=0;i<10;i++){
    printf("%4d|",c++);

    for(j=0;j<10;j++){
    printf("%4c",board[i][j]);}
    printf("\n\n");}

    printf(" +---+---+---+---+---+---+---+---+---+---+\n\n");
    }

    /*---------------------------------------------------------------------------
    -----------------------------------------------------------------------------*/




    int main(argc, argv)
    int argc;
    char *argv[];
    {
    char board1[10][10];
    char player;
    printf(" Player1\n\n");
    print_board(board1);
    get_imput(player);


    char board2[10][10];
    printf(" Player2\n\n");
    print_board(board2);

    exit(0);
    }

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,354

    Re: Placing Battleships PSPAD C++

    Please, don't multipost!
    I already answered you in your other thread with the same question here
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center