0

I am attempting to do the following problem below:

enter image description here

I have made my code as the following to attempt to follow the instructions but I'm having issue with that and have done this instead:

//Include statements
#include <iostream>
#include <string>
using namespace std;

//Global declarations: Constants and type definition only -- no variables

//Functions prototypes


int main()
{
    //Variable declarations

    int factorial(int n);
    int factorial(int r);

    int main();

    double n = 18.0;
    double r = 3.0;

    //Program logic

    cout << "Hello there, stranger! How are you today?" << endl;
    cout << " " << endl;
    cout << "I am here to inform you that the number of teams that can be arranged is: "
        << factorial(n) * factorial(r) << endl;


    //Closing program statements
    system("pause");
    return 0;
}
//Function definitions

I am getting this error:

Error   LNK2019 unresolved external symbol "int __cdecl factorial(int)" (?factorial@@YAHH@Z) referenced in function _main

Can someone tell me what this means and how to fix it? Thank you!

  • Does this answer your question? [Unresolved external symbol in object files](https://stackoverflow.com/questions/9928238/unresolved-external-symbol-in-object-files) – rsjaffe Mar 27 '20 at 17:58
  • I think the issue is the double-declaration of `int factorial(int)` and the declaration of `int main()` *within* the `main()` function. You probably meant to only have ONE forward declaration of `int factorial(int)` above the `main()` function. The `int main();` within main doesn't do anything sensible, remove it. I'm assuming you have a function definition for `int factorial(int)` below? – JohnFilleau Mar 27 '20 at 18:01
  • Note that you MAY declare a function within another function (like you're currently doing), but it's not common, and if you ever need to do that you should be at a familiarity with the language that you understand when. – JohnFilleau Mar 27 '20 at 18:04
  • the declarations are weird, but the problem is that you dont define the function. How is the compiler supposed to know what to do when you call `factorial`? – 463035818_is_not_an_ai Mar 27 '20 at 18:05
  • I think you made some wrong deductions of what your teacher, book or tutorial have told you. You also need to learn the difference between a *declaration* (telling the compiler that something exists) and a *definition* (giving the compiler the implementation). – Some programmer dude Mar 27 '20 at 18:06
  • you need some code somewhere to calculate the factorial – 463035818_is_not_an_ai Mar 27 '20 at 18:07
  • I tried to get some examples online to help me try to write this. The issue is that I don't understand how I'm supposed to do factorials in here. I may have placed things wrong as well but I'm still attempting to learn. I don't think doing this just online is helping me much either. – Firerad Fieritis Mar 27 '20 at 18:10
  • Anyone know where to direct me to help figure out how to calculate the factorial? – Firerad Fieritis Mar 27 '20 at 18:11
  • The issue isn't the book. It's the fact that I don't think learning online without direct help from a teacher in a classroom is being as effective as liked. I just need someone to explain to me what I'm doing wrong then I can try to fix the issue I'm having. – Firerad Fieritis Mar 27 '20 at 18:25

0 Answers0