Can someone tell me what im doing wrong?

Complete the function definition to return the hours given minutes. Output for sample program when the user inputs 210.0:
3.5

My code:

#include <iostream>
using namespace std;

double GetMinutesAsHours(double origMinutes) {

cout << origMinutes/60;

}

int main() {
double minutes;

cin >> minutes;

// Will be run with 210.0, 3600.0, and 0.0.
cout << GetMinutesAsHours(minutes) << endl;

return 0;
}

It’s outputs as:

3.53.03428e-86
Learn to use code tags, they make reading and commenting on source code MUCH easier.

How to use code tags: http://www.cplusplus.com/articles/jEywvCM9/

There are other tags available.

How to use tags: http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

Some formatting & indentation would not hurt either
One problem that stands out is you contracted to return a double from your function, yet you are not returning anything. You are printing out a garbage value.

Your compiler is not doing you any favors. It should either issue a warning, or in the case of Visual Studio the code you wrote will have a compile error.

Something like this should work:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

double GetMinutesAsHours(double origMinutes)
{
   return origMinutes / 60.0;
}

int main()
{
   std::cout << "Enter the # of minutes you want converted to hours: ";
   double minutes;
   std::cin >> minutes;

   std::cout << GetMinutesAsHours(minutes) << " hours.\n";
}
Enter the # of minutes you want converted to hours: 75
1.25 hours.

Using code and output tags helps to make things much more readable.
Last edited on
Topic archived. No new replies allowed.