Nume Awesome Nume Awesome - 1 year ago 80
C++ Question

Check if is alive

Hello there today I wanted to create an array which is named area and a ship after I run it shows me -85838253 and I want to see after I run it "ship it's on water" but I don't see where I'm wrong and why it's not working ...
Code i used :

int area[5]; // this means to be the water
int ship=5;
area[0] = { 0 };
area[1] = { 1 };
area[2] = { 2 };
area[3] = { 3 };
area[4] = { 4 };

int v[5], i, found = 0;
i = 1;
while ((i <= ship) && (!found))
{
if (area[i] == ship) found = 1;
i++;
}
if (found) cout << ship << "ship it's on water";
else cout << ship << "ship it's not anymore on water";


Thanks :D

Answer Source
 int area[5]; // this means to be the water
area[0] = { 0 }; // wrong assignment 

Either you can do

int area[5] = {0,1,2,3,4};

Or

int area[5]; // this means to be the water
area[0] = 0;    
area[1] = 1;
..................
area[4] = 4;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download