[cs23021-2] lab6 question

Mikhail Nesterenko mikhail at cs.kent.edu
Mon Oct 12 19:04:08 EDT 2009


> The direction is "Define a function entry that asks the user to
> enter a single number from 1 to 100.  This function should take the
> user entry as a call-by-reference parameter.  Define a function
> check that takes the number input and array wins as *parameters and
> returns the index of the array element that matches the input number
> or zero if none of the elements do*." I got confused at why user
> enter 1 to 100, I thought would be 1-99? so user enter 1 number to
> see it matches any number in wins[], and return wins[#]?

It is a typo. I just corrected it. The number should go from 0-99. The
random numbers in this range are easily obtained if you take a
remainder of the division of a large random number (returned by
rand()) by 100. If you used 1-99 or 1-100 range you do not have to
redo the lab, no points will be deducted for it.

The function entry() should ask the user for a single number and
return it to main() in the form of a call-by-reference parameter. For a
single scalar value it would have been better to use the return value
of a function, but this way you practice using call-by-reference.

The parameters for function check() should be the array, and the user
entry (as a separate scalar parameter). Function check() should return
either:

- the index of the array element that matches the user entry, or
- zero (to signify that the element was not found). Note that
  this clashes with the first index in the array. If you did not
  check for this condition, you do not have to redo the lab,
  no points will be deducted for it. However, a proper return
  value should probably be minus one.

  The function check() may return the result either as a return value 
  call-by-reference parameter. Both variants are acceptable.


Thanks,
--
Mikhail


More information about the cs23021-2 mailing list