redefinition of 'int main()'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pojbgh
    New Member
    • May 2021
    • 2

    redefinition of 'int main()'

    I have this code. write a code that asks for a number and define 2 functions. the first must return the remainder of the number by dividing by 7 and the second must return the day of the week (0 =Sunday 1=Monday .. 6=Saturday). so far i have done this:

    BUT when i run it , it gives me this error --> redefinition of 'int main()' what does this mean and what do i have to fix?
    Code:
    #include <iostream>
    using namespace std;
    
    int myNumbers(int a)
    {
        return a % 7;
    }
    void myFuction(string);
    int main()
    {
        int a;
        cout << "give a number between 0-6: \n";
        cin >> a;
        cout << "the result is " << myNumbers(a);
    }
    
    int main()
    {
        myFuction("sunday");
        myFuction("monday");
        myFuction("tuesday");
        myFuction("thursady");
        myFuction("wendsday");
        myFuction("friday");
        myFuction("saturday");
        return 0;
    
        cout << "then day is:" << myFunction();
    }
    Last edited by Banfa; May 24 '21, 09:24 AM. Reason: Added code tags
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 655

    #2
    I have this code. write a code that asks for a number and define 2 functions. the first must return the remainder of the number by dividing by 7 and the second must return the day of the week (0 =Sunday 1=Monday .. 6=Saturday). so far i have done this:

    BUT when i run it , it gives me this error --> redefinition of 'int main()' what does this mean and what do i have to fix?
    Code:
    #include <iostream>
    using namespace std;
    
    int myNumbers(int a)
    {
    return a % 7;
    }
    void myFuction(string);
    int main()
    {
    int a;
    cout << "give a number between 0-6: \n";
    cin >> a;
    cout << "the result is " << myNumbers(a);
    }
    
    int main()
    {
    myFuction("sunday");
    myFuction("monday");
    myFuction("tuesday");
    myFuction("thursady");
    myFuction("wendsday");
    myFuction("friday");
    myFuction("saturday");
    return 0;
    
    cout << "then day is:" << myFunction();
    }
    - Function names must be unique.
    - The statement below return 0; is not effective.
    - myFuction() has no body.
    - Watch out for the typos : myFuction() or myFunction() and also, arguments while calling.
    - The day is probably not to be passed as argument.

    Comment

    Working...