Convert minutes to Hours AND minutes with my code

DizzybeeDizzybee Bucharest
edited June 2014 in Beginner C/C++

Hi people,
I'm trying to do this small program for at least 2 hours and that's what I got so far. It should convert minutes to hours AND minutes:

 #include <iostream>
using namespace std;

int Transform(int c);

int main()
int rezultat2;

cout<<"90 minutes means "<<a<<" hours and "<<b<<" minutes\n";
return 0;

int Transform(int c)
    int a=c/60;
        double b=c%60;

        return result;

*I know I shouldn't use masking variables as I don't want to get used to it 'cause It will get dificulties errors for more advanced programs.
*only one function should be used (apart from main) - only in case there's no other way
*should be as simple as possible with as few code lines as possible....
Any idea where am I doing wrong?
I've tried to look on other topics but I didn't understand, and besides I want to understand and remember with my code....


  • Have you attempted to compile the code? You should post any compiler errors you get along with the code. Sometimes they can be rather cryptic but it would behoove you to learn how to interpret them, it is an extremely valuable skill to acquire and many of us starting out only get that through repeated exposure/experience. It's very likely the error/warning messages would clearly direct you to where at least some of the problems are.

    1. The variables "a" and "b" are local to the function Transform, they cannot be accessed outside of that function.
    2. There should be no reason that the minutes variable "b" needs to be declared as double.
    3. The variable "result" has not been declared.
    4. There currently seems to be no reason for your function to return a value at all (though this could change depending on what further steps you take); and consequently, no need to have a variable declared in main to receive that return value.

    In general:
    Since a function can only return a single item and your function seems to need to return two values (an hour an a minute value) then you probably need to pass in two more values (declared in main) that will be used to store those results. Since the function is going to be modifying these two values, they will need to be passed using pointers.
    Alternately, your function can return a single struct consisting of two members (an hour and a minute) instead of passing an additional two parameters.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion