4 Replies - 5901 Views - Last Post: 10 July 2009 - 06:26 PM Rate Topic: -----

#1 agp12  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-July 09

battleship c/c++ program

Post icon  Posted 10 July 2009 - 05:55 PM

this is it....

i have a problem in 2 dimensional array and a random generator number,,,can u guide me to have an idea on how to generate random number? becouse we are making a battleship program in c/c++ thank you... here is what the program outputs FOR player one and pc.

A B C D E
1
2
3
4
5

Enter coordinate:
<then the pc will give then a move in fighting with me
Is This A Good Question/Topic? 0
  • +

Replies To: battleship c/c++ program

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1147
  • View blog
  • Posts: 7,132
  • Joined: 07-September 06

Re: battleship c/c++ program

Posted 10 July 2009 - 06:17 PM

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: :code:

Thanks.
Was This Post Helpful? 0
  • +
  • -

#3 mono15591  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 406
  • Joined: 05-November 08

Re: battleship c/c++ program

Posted 10 July 2009 - 06:21 PM

Google
C++ rand
First Google link listed
Was This Post Helpful? 0
  • +
  • -

#4 ccubed  Icon User is offline

  • It's That Guy
  • member icon

Reputation: 160
  • View blog
  • Posts: 1,403
  • Joined: 13-June 08

Re: battleship c/c++ program

Posted 10 July 2009 - 06:24 PM

The three functions used for random numbers are srand, rand and time (usually). These are contained in cstdlib and there are tons of tutorials for it.

As for the 2D array, if all you need is something simple, then this does it.

//<data type> <identifier>[<rows>][<columns>];

//example

char a[2][2]; //2x2 array of chars.



This post has been edited by ccubed: 10 July 2009 - 06:24 PM

Was This Post Helpful? 0
  • +
  • -

#5 apw5020  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 666
  • Joined: 26-March 09

Re: battleship c/c++ program

Posted 10 July 2009 - 06:26 PM

2d array: char someArray[numRows][numColumns];

Random number generator:
#include <cstdlib>
#include <ctime>
int main()
{
srand(time(NULL));
int randomNum = rand() % randomLimit;
return 0;
}



There's a headstart, now get coding!

This post has been edited by apw5020: 10 July 2009 - 06:30 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1