[cs13001] Options

Mikhail Nesterenko mikhail at cs.kent.edu
Thu Oct 25 10:18:07 EDT 2012


> Can you help me out with location fire? I'm having trouble calling
> the check function after inputting my x and y coordinates.

Make sure that in the definition of fire() you create a structure
variable of type location to return. There can be several ways to
invoke fire. For example:

    location shot;
    shot = fire(); 
    int isHit = match(battleFleet, shot);
    if(isHit != -1 ) ...  // process hit
    

Or by initializing "shot" at declaration and skipping the result variable:

   location shot=fire();
   if(match(battleFleet, shot) != -1) ... // process hit


Or even more terse, skipping the result variable altogether:

   if(match(battleFleet, fire()) != -1) ... // process hit


Thanks,
--
Mikhail


More information about the cs13001 mailing list