#include <iostream>
using namespace std;
int main(){
bool ships[3][4]={{0,1,0,1},{1,0,0,1},{1,0,1,0}};
int n=1,t=0,guess=0,maxship=1;
while (n!=0)
{
cout<<"Enter cordinates of the ship row-(0-2),col-(0-3): ";
int c,b;
cin>>c>>b;
if (ships[c][b]==1)
{
cout<<"You hit the ship"<<endl;
t++;
ships[c][b]=0;
if (maxship>5)
{
cout<<"you guessed all the coordinates in the perfect number: "<<endl;
break;
}
maxship++;
}
else
{
cout<<"nearly miss next try:"<<endl;
}
cout<<"You want to continue press 1 for exit=0: ";
cin>>n;
guess++;
}
cout<<"Your number of hit:"<<t<<endl;
cout<<"number of guesses:"<<guess;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter