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

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 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?

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