M
M
Makar Gerasimov2016-06-02 00:56:43
C++ / C#
Makar Gerasimov, 2016-06-02 00:56:43

How to generate real numbers?

Hello.
I can’t figure out how to generate real numbers so that they fit the conditions:
1) Number of the form: 00.00
2) Before the comma (integer) from 1 to 24
3) After the comma (hundredths) from 01 to 59
This is a kind of time for the schedule calls))

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fat Lorrie, 2016-06-02
@MacFiss

double getMyTime(int hours, int minutes) {
  if (hours  <= 0 || hours > 24) {
    throw InvalidArgumentException("hours");
  }
  if (minutes  < 0 || minutes > 59) {
    throw InvalidArgumentException("minutes");
  }
  return hours + minutes / 100.;
}

A
Alexey, 2016-06-02
@alsopub

Not a very clear task.
If you need a random number, then alternatively generate two integer random numbers, one from 0 to 23, the other from 0 to 59. Your result will be A + B/100.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question