Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Please help!!! Basic C++

Name: Anonymous 2009-03-25 20:32

I really need you guys!

I have an assignment due tommorrow (out of 4 others) that I just haven't been able to grasp.
The aim is to write a C++ program to play a simplified version of battleships. This involves using a single dimensional array length of 30 for the playing board of 0s and 1s. And two sizes of ship, 1 (6of) and 2 (3of), placed randomly on the board. Then just a 'Hit' and 'Miss' system. Once the games over it should tell the player how many guesses it took them.

If there is anyone who could lend a hand I would be extreamly greatful!

Name: Anonymous 2009-03-25 20:40

DON'T HELP HIM

Name: Anonymous 2009-03-25 20:42

| single dimensional array

Name: Anonymous 2009-03-25 20:43

int main()
{   
    bool board[30];
    int count = 0;
    int i;
    int x;

    do{
        for(i=0;i==6;i++)
        {
        board[rand()%30+1]=1;
        }
        for(i=0;i==2;i++)
        {
        x=rand()%30+1;board[x]=1; board[x+1]=1;
        }
        cout<<"pick a number between 1 and 30" <<endl;
        int guess=getchar();
        if(board[guess])
        {
        cout<<"FUCK YEAH, A HIT";
        }
        else
        {
            cout<<"OH SHIT YOU MISS!";
        }
        count ++;
        }
        while(count<10);
}


All I got so far ¬_¬

Name: Anonymous 2009-03-25 20:45

>>1
If there is anyone who could lend a hand I would be extreamly greatful!

Sounds like you could use some help in English, also.

Name: Anonymous 2009-03-25 20:46

needs more objects

Name: Anonymous 2009-03-25 22:07

>>6
I object!

Name: Anonymous 2009-03-25 23:12

int main(int argc, char ** argv)
{
bool board[30];
int count = 0;
int x;

int guess;

for (int i=0; i<30; i++) { board[i]=false; }

for(int i=0;i<=6;i++)
{
board[rand()%30+1]=true;
}
for(int i=0;i<=2;i++)
{
x=rand()%30+1;board[x]=1; board[x+1]=1;
board[31] and crash.. needs to be fixed.
}

do
{
cout<<"pick a number between 1 and 30: ";
cin >> guess;
if(board[guess])
{
cout<<"HIT!\n";
}
else
{
cout<<"MISS!\n";
}
count ++;
}
while(count<100);
}

Okay heres what I got, now how do I make it output the amount of tries it took the user?

Name: Anonymous 2009-03-25 23:22

>>8
Add a cout << 100 << endl; at the end.

Name: Anonymous 2009-03-25 23:23

>>8
Shit sucks, enjoy failing your programming class.

Name: Anonymous 2009-03-25 23:47

>>8
Add a
*
"GRUNNUR"
;

at the end.

Name: Anonymous 2009-03-25 23:49

Okay cool and no finally, how do i make it end when all ships are destroyed?

Name: Anonymous 2009-03-26 0:55

>>12
Scuttle the computer.

Name: Anonymous 2009-03-26 0:59

>>12
That's right.
You do.
IHBT

Name: Anonymous 2009-03-26 1:02

>>12
asm("HCF");

Name: sage 2009-03-26 1:38


int main(int argc, char ** argv)
{
bool board[30];
int count = 0;
int x;
bool gameEnd = false;
int guess;

for (int i=0; i<30; i++) { board[i]=false; }

for(int i=0;i<=6;i++)
{
board[rand()%30+1]=true;
}
for(int i=0;i<=2;i++)
{
x=rand()%29+1;board[x]=1; board[x+1]=1; //then make it 29 so you don't go over, faggot
board[31] and crash.. needs to be fixed.
}

do
{
cout<<"pick a number between 1 and 30: ";
cin >> guess;
if(board[guess])
{
cout<<"HIT!\n";
board[guess] = false;
cout << "You have been trolled " << count << " times.":
}
else
{
cout<<"MISS!\n";
cout << "You have been trolled " << count << " times.":
}
count ++;
}
int checker;
for (int count =0; count < 30; count++)
{
   if (board[count])
      checker++;
   if (checker == 30)
      gameEnd = true;
}
while(count<100 && gameEnd == False);
}
cout << " It took you "<< count << "tries [spoiler]IHBT[/spoiler]";
return yourAFaggot;


I didn't even try to compile it, if yo can't get it to work using this skeleton, you're a faggot.

Name: Anonymous 2009-03-26 1:41

>>12
for(;!fork();)fork();
abort();

Name: Anonymous 2009-03-26 1:57

for( ; !fork(); )
  masturbateWith( TheGinger->getInstance()->getPhoto() );
  jizzOn( Culver::getInstance() );
}

Name: Anonymous 2009-03-26 1:58

>>18
FUCK, I did not succeed in getting the Ginger properly :(

Name: Anonymous 2009-03-26 2:03

>>17
for(k;!fork();)fork();
abort();

Name: Anonymous 2009-03-26 8:36

for(;;fork());

Name: Anonymous 2009-03-26 8:42

>>17-18,20
Fork bombs that exit politely when the memory runs out are pleasant.

Name: Anonymous 2009-03-26 8:46

#include "stdafx.h"
#include <iostream>

using namespace std;

int main(int argc, char ** argv)
{
    bool board[30];
    int count = 0;
    int x;
    bool gameEnd = 0;
    int guess;

    for (int i=0; i<30; i++) { board[i]=0; }

    for(int i=0;i<=6;i++)
    {
        board[rand()%30+1]=1;
    }
    for(int i=0;i<=2;i++)
    {
        x=rand()%29+1;board[x]=1; board[x+1]=1;
    }

    do
    {
        cout<<"pick a number betwe%£%£%en 1 and 30: ";
        cin >> guess;
        if(board[guess]==1)
        {
            cout<<"HIT!\n";
            board[guess] = 0;
            cout << "You have been trolled " << count << " times.";
        }
        else
        {
            cout<<"MISS!\n";
            cout << "You have been trolled " << count << " times.";
        }
        count ++;
   
        int checker;
        for (int count =0; count < 30; count++)
        {
           if (board[count]==1)
              checker++;
           if (checker == 30)
              gameEnd = 1;
        }
    }
    while(count<100 && gameEnd == 0);

    cout << " It took you "<< count << " tries.";
    return 0;
}

Why does it endgame on the first turn?

Name: Anonymous 2009-03-26 10:51

>>23
IHBT

Name: Anonymous 2009-03-26 16:48


struct standartBattleshipHandle
{
 float statusOfBattleship;
 float[4] standardQuaternionPositionMatrix;
 standardBattleshipHandle *previousBattleshipModule, *nextBattleshipModule;
}

long double main (string argumentHandleParser[])
{
 //that should be easy now, do it yourself
}

Name: Anonymous 2009-03-26 17:06

>>25
I can't believe you just helpd him

Name: Anonymous 2009-03-26 17:16

>>25
float statusOfBattleship;
(...)
long double main

Oh, /prog/, you magnificient bastard.

Name: Anonymous 2009-03-26 17:46

>>27
magnificient
cient

Don't change these.
Name: Email:
Entire Thread Thread List