Maker Pro
Maker Pro

Don't Laugh..shot in the dark at my battleship game (not complete)

OK. So this is my first attempt at writing a battleship style game in C++. Ive got the int main() intro section to run smoothly on its own but int game() is a mess so far and is riddled with errors. Im in need of some guidance here. The goal is to get the computers ships all defined and placed at random coordinates each time the program runs. Afterwards ill integrate the players ships and let the player choose where to place them at the start of the game. Go easy on me, im unclear on how to use the rand() and srand() functions, let alone randomize x,y coordinates. I would really apreciate any guidance here guys, or atleast some resources to help me understand how to structure this game of mine.
Thanks !
 
whoops forgot the code...
Code:
// BattleShip


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


using namespace std;

int main() // Start Program
    {

    cout << "BATTLESHIP" << endl;
    getchar();
    system("CLS");
   
   

cout << "Enter your name" << endl;

string player;

cin >> player;        // Player enters name


cout << "OK " << player << ", " << "are you ready to play?" << endl;

int start;
int y;
y = 'y';
cin >> start;
system("CLS");
if (start = y);
cout << "Begin!" << endl;
else
cout << "OK, see you next time";

system("pause");

int game()
{

    int battleship;
    int cruiser;
    int tugboat;
    int corvette;
    int carrier;
    battleship = srand(50 % 1, 50 % 1);
    cruiser = srand(25 % 1, 25 % 1);
    tugboat = srand(10 % 1,10 % 1);
        corvette = srand(100 % 1,100 % 1);
    carrier = (75 % 1, 75 % 1);
    int playerguessx;
    int playerguessy;
    cout << "Choose x coodordinate (1-100)";
    cin >> playerguessx;
    system("CLS");
    cout << "Choose y coordinate (1-100)";
    cin >> playerguessy;

    if (playerguessx, playerguessy = battleship)
    cout << "You sunk my Battleship!";

    else if (playerguessx, playerguessy = cruiser)
    cout << "You sunk my Cruiser!";

    else if (playerguessx, playerguessy = tugboat);
    cout << "You sunk my tugboat!";
    else if (playerguessx, playerguessy = corvette);
    cout << "You sunk my Corvette!";
    else if (playerguessx, playerguessy = carrier);
    cout << "You sunk my Carrier!";
    else
        cout << "miss";





}




   
   

        return 0;


}
 
Top