0
#include<iostream>

using namespace std;
int hour(int h)
{
    int second;
    //second=(h/3600);
    if (h>3600)
        second=h/3600;
    else 
       second=(h/3600);
    return (second);
}

int minute(int m)
{
    int second2;
    second2=(   );
    return(second2);
}

int second(int s)
{
    int second3;
    second3=((s-3600)%60);
    return (second3);
}

void main()
{
    int convert;
    cout<<"please enter seconed to convert it to hour\b";

    cin>>convert;
    cout<<"hr : min : sec \n";
    cout<<hour(convert)<<":"<<minute(convert)<<":"<<second(convert)<<endl;
    system("pause");
}

thanks for the help, this is supposed to convert seconds to minutes to hours but it doesnt seem to work properly.again, sorry if its super simple i just started learning c++ this year and a lot of stuff confuses me

Farbod Ahmadian
  • 618
  • 5
  • 16
  • 2
    Global `main()` function in C++ must return `int`, as the message says. – MikeCAT May 15 '20 at 14:17
  • 1
    The error pretty much speaks for itself. `void main()` must be replaced with `int main()`. – HolyBlackCat May 15 '20 at 14:17
  • @HolyBlackCat that worked for the int main, but im also having a problem with second2=( ); i put a value in there then it doesnt seem to do anything – Charles McGill May 15 '20 at 14:20
  • Saying "it doesn't seem to do anything" is not a helpful problem description. Were you able to compile it? Did the code execute? Were you able to provide input? Did you get output? Was the output not what you expected? What did you expect? What did you get? – David Schwartz May 15 '20 at 14:48
  • @CharlesMcGill Also when code doesn't work, don't leave it blank, post the code that doesn't work, that the part we need to see in order to understand the problem or explain what went wrong. – john May 15 '20 at 15:00

1 Answers1

1

As the error message says, the main function should always return int.

int main()
{
    int convert;
    cout<<"please enter seconed to convert it to hour\b";

    cin>>convert;
    cout<<"hr : min : sec \n";
    cout<<hour(convert)<<":"<<minute(convert)<<":"<<second(convert)<<endl;
    system("pause");

    return 0;
}
Acc-lab
  • 194
  • 15
  • 1
    The return statement is not required in `main` in C++ (and C99 and above if I remember correctly) – Mat May 15 '20 at 14:21
  • 1
    @Mat It's not required, but it's still a good habit to add `return 0;` in the main function. – Acc-lab May 15 '20 at 14:23
  • *"a good habit"* Why? – HolyBlackCat May 15 '20 at 14:30
  • @HolyBlackCat https://www.quora.com/Why-do-we-use-a-return-0-at-the-end-of-a-main-function – Acc-lab May 15 '20 at 14:31
  • I've checked the first few answers, and none of them actually explain that. Some of them explain what the return codes are for, and some incorrectly claim that `return 0;` can't be omitted here. – HolyBlackCat May 15 '20 at 14:38
  • @HolyBlackCat I would say `return 0;` means this program ends sucessfully. But you can still choose if you want to write it or not. – Acc-lab May 15 '20 at 14:40
  • 1
    @Acc-lab • if omitted, `return 0;` is implied. Omitting it is a good habit, unless needed otherwise, because it's just ceremonious syntactical noise. (If I were to put it in, I'd say `return EXIT_SUCCESS;` since that's semantically what the magic 0 means.) – Eljay May 15 '20 at 15:59
  • @Acc-lab: That quora link you posted is full of misinformation. – TonyK May 15 '20 at 18:33
  • @Eljay I understand it can be ommited, it's just a habit (maybe for begginers) to remember what does `return` do in main function. Also it's true that `return EXIT_SUCCESS` seems more intuitive than `return 0`. – Acc-lab May 16 '20 at 01:30
  • @TonyK I just noticed it, but you can see the comment from me above – Acc-lab May 16 '20 at 01:31