Give me some suggest please!

This is a discussion on Give me some suggest please! within the C++ Programming forums, part of the General Programming Boards category; Write a program to simulate the battle ship game. You have a 10x10 area and three battle ships are randomly ...

  1. #1
    Unregistered
    Guest

    Give me some suggest please!

    Write a program to simulate the battle ship game.
    You have a 10x10 area and three battle ships are randomly
    located.
    Each ship occupies 5 consecutive elements and it can have
    different orientations.
    The player is allow to make 3 hits, by inputting the (x,y)
    coordinate. The program will notify the player his score at
    the end of the game.
    Your program must save the 10x10 map into a file. In the file
    Use o to represent element of a battle ship and x to mark
    location hitted by the player

    my teacher asked me to use
    srand(time(0))
    this function
    i have tried,
    but I don't know how to continue...
    Can anyone gives me some suggestion how I can do? Thx!~

  2. #2
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    srand() sets the start point for generating random numbers.
    rand() generates a random number.
    time() gets the system time.

    The reason srand() is called using time() as the [araemter a lot is to produce a new number on each call so that the numbers remain random each time the program is run.

    Syntax
    time_t time( time_t *timer );

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <time.h>
    
    int main(void)
    {
       int i;
    
       /* Seed the random-number generator with current time so that
        * the numbers will be different every time we run.
        */
       srand( (unsigned)time( NULL ) );
    
       /* Display 10 numbers. */
       for( i = 0;   i < 10;i++ )
          printf( "  %6d\n", rand() );
    }
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  3. #3
    Unregistered
    Guest
    Originally posted by lightatdawn
    The reason srand() is called using time() as the [araemter a lot is to produce a new number on each call so that the numbers remain random each time the program is run.
    I'm sorry, I don't understand these sentenses. Can u explain it one more time, please? Thanks!

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    72
    Hi
    this is a good thread about the srand(), so check it

    http://www.cprogramming.com/cboard/s...4621#post32861

  5. #5
    Unregistered
    Guest
    Thanks you guys!!~

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. please give ur point of view
    By clover in forum C Programming
    Replies: 2
    Last Post: 05-04-2004, 03:56 PM
  2. Give me some opinions on setting up a server
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 04-19-2004, 10:38 AM
  3. Can you give me your tip plz :)
    By dionys in forum C Programming
    Replies: 6
    Last Post: 04-11-2004, 11:14 PM
  4. How To Give A Font Colour ?
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 09-14-2001, 01:22 PM
  5. Just to give you an idea of what we're going through...
    By rick barclay in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 09-13-2001, 02:09 PM

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