1

I have been trying to get this code working. I have made this code mostly myself and google. I am very beginner in this, so I have no idea how to fix this.

I have tried cutting code, transforming it to c#,(modifying it of course) new file and different compiler.

#include <iostream>
using namespace std;

//suurin_luku.cpp 

int question() {
    double answers;
    cout << "Do you want the biggest number, or smallest number?\n";
    cout << "0 for biggers, 1 for smaller.\n";
    cin >> answers;

    if (answers == 0) {
        int biggest();
    }
    if (answers == 1) {
        int smallest();

    }
    return 0;
}






int biggest()
{
    float input1, input2, input3;
    cout << "Please insert three numbers.\n";
    cin >> input1 >> input2 >> input3;
    if (input1 >= input2 && input1 >= input3)
    {
        cout << "The largest number is: " << input1;
    }
    if (input2 >= input1 && input2 >= input3)
    {
        cout << "The largest number is: " << input2;
    }
    if (input3 >= input1 && input3 >= input2) {
        cout << "The largest number is: " << input3;
    }
    return 0;
}

int smallest()
{
    float input11, input22, input33;
    cout << "Insert three numbers.";
    cin >> input11 >> input22 >> input33;
    if (input11 <= input22 && input11 <= input33)
    {
        cout << "The smallest number is: " << input11;
    }
    if (input22 <= input11 && input22 <= input33)
    {
        cout << "The smallest number is: " << input22;
    }
    if (input33 <= input11 && input33 <= input22) {
        cout << "The smallest number is: " << input33;
    }
    return 0;
    }

When user inputs 0, it shows the largest inputted number. When user inputs 1, it shows the smallest inputted number. Error codes are LNK1120 and LNK2019.

Blaze
  • 16,736
  • 2
  • 25
  • 44
Kristian
  • 33
  • 5
  • 1
    When asking questions about build errors (which is what you have) then you should copy-paste (as text!) the full and complete build output into the question itself. And if they happen on specific lines, add comments in the code on those lines. Also please take some time to read about [how to ask good questions](http://stackoverflow.com/help/how-to-ask), as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). – Some programmer dude Aug 28 '19 at 07:06
  • What are the messages of LNK2019 and LNK1120? – RoQuOTriX Aug 28 '19 at 07:06
  • Where's your `main` function? Did you get "hello world" to work? – Bathsheba Aug 28 '19 at 07:07
  • And what do you mean by " transforming it to c#"? The code you show isn't C#... How is C# involved? – Some programmer dude Aug 28 '19 at 07:07
  • 1
    And you should probably invest in [a few good books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/388282#388282) to read, because whatever tutorials you have read clearly isn't enough (you make some very basic mistakes that good books, or classes, should have taught you not to do). – Some programmer dude Aug 28 '19 at 07:09
  • Thank you guys for feedback. I will try to learn more about coding. – Kristian Aug 28 '19 at 07:19

1 Answers1

1

If that's all of your code, then you probably get the linking errors because you're missing a main function. I get those exact two linking errors if I omit main on my VS project. Add this to your code:

int main() {
    question();
}

Also, you're not calling your functions, you're just declaring them:

if (answers == 0) {
    int biggest();
}
if (answers == 1) {
    int smallest();
}

Remove those int to call the functions. You'll have to put int question() below those two other functions or it won't find them, unless you declare them beforehand, like this:

int biggest(); // declaring them so question() knows their signature
int smallest();
int question() { ... }; // question() calls biggest() and smallest()
int biggest() { ... }; // actual implementation of those functions
int smallest() { ... };
int main { ... }
Blaze
  • 16,736
  • 2
  • 25
  • 44