Need help with function.

I need help creating with the conversions. Here’s the question?
A function called eta( ) which takes a distance in miles and a speed in MPH and returns a string that displays the hours and minutes until arrival. So a function call to eta(80,55) should return the string "1 Hour 27 Minutes".
Do you know how to calculate the amount of time it takes to go 80 miles if you're travelling at 55 MPH?
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <string>
#include <iostream>
std::string eta(const int distance, const int speed){
      int hour{}, minutes{};
    // get hour and minutes from distance and speed
    return std::to_string(hour) + " Hour " + std::to_string(minutes) +" minutes.";
}

int main(){
    std::cout << eta(80, 55) << std::endl;
    
    return 0;
}


Hope that helps.
Last edited on
here is what i currently have. minutes are not working though.


string mph(int distance, int speed)
{
int milesPerhours = (distance/ speed);
int temp = ((distance/ speed ) * 60);
int minutes = (temp - (milesPerhours / 60));
string eta = to_string(milesPerhours) + " hours " + to_string(minutes) + " minutes ";
return eta;
}

What does "not working" mean? Give us a clear and precise description of what your problem is, to make it easier for us to help you.

You're doing lots of integer division there, which means you're likely to get some unexpected results. I'd recomment using floats rather than ints for your numerical values.
here is the full thing. also i mean that my minutes are not correct. i am getting the wrong time. any help would be appreciated.

http://cpp.sh/7d4lm

If you'd read all the way to the end of my previous post, you'd already have some of the help you're looking for.
haha. thanks Mikeyboy your right. had to change the parameters to floats.
You're welcome.
Topic archived. No new replies allowed.