Hi, is it possible to have int method and get double value from it?
Norm Radder wrote:
Hi, is it possible to have int method and get double value from it?
No and Yes.
A method can only return one type of value: int or double
The problem can be changed to return an index into a list of values so the type of the values is not used.
Pass a list of values to the search method and have it return the index into the list of the desired value.
Then the calling code can use that index to access the found value from the list.
Was there an average() method? That can't return an int index.Norm Radder wrote:. . . the search methods can return an index into the list/array of the found value. . . .
Campbell Ritchie wrote:Welcome to the Ranch
Please explain why you have methods returning ints when the values are not ints. Why do you need to return ints at all?
Norm Radder wrote:Can the values be placed in a list or an array?
Can the methods be given access to that list or array?
If so the search methods can return an index into the list/array of the found value.
For example it the array contained: {11.2, 2.3, 33.7}
The index for the smallest value would be 1
the index for the largest value would be 2
Campbell Ritchie wrote:Was there an average() method? That can't return an int index.
all methods can access to the array
Campbell Ritchie wrote:Please check carefuly that you have understood the assignment correctly. Can you make the scores into ints? For the average to be an int, you would have to round it.
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
No, I got that wrong sorry.Norm Radder wrote:I missed where the average must be an int.
I saw: . . .
highest and lowest values must be returned as ints?
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
Norm Radder wrote:
Campbell Ritchie wrote:Was there an average() method? That can't return an int index.
Note: I said "search" methods.
all methods can access to the array
Ok, then the search methods can return an index into the array. An index is an int value
how do you return an index?
return array[i]; // return value in array at index i
how do I get the winner after i compare the average computed?
That's a pleasureJunshi Gusza wrote:thanks . . .
Well done: please show us the finalproduecti solved it.
No. We only delete threads which have something wrong with them.. . . . is it possible to delete this thread?
Consider Paul's rocket mass heater. |