Hey guys,
I'm about 2 months into c++ and I've written a fairly simply code for the High Low Game in which the system generates a number and the user has to guess the number.
However, fatal error LNK1120: 1 unresolved externals keeps coming up.
Any help would be appreciated.
Thanks in advance
What exactly is the error? (hang on - let me guess)
To use rand(), you need to have #include <cstdlib> in there.
Also, it should be int main(), not void main().
And since it's C++ (not C), you can (should?) also just put #include <ctime> , rather than #include "time.h" (but nothing will happen in this case if you just leave it as it is).
Don't give us the abridged version of the error. Give us the entire error. You left out the most important part of the error message (ie: what symbol the linker is failing to find) so it's impossible for us to help you solve it.
Also, there are a lot more problems with this than just the linker error. In addition to what "long double main" said....
- don't call srand before every call to rand. srand should be called exactly ONCE. Don't call it for every random number.
- Your while loop on line 31 is missing an open brace.
- why do you have a loop: label and matching goto? You're already inside a while loop! Just let the while loop keep the loop going -- that's what it's there for.
- I don't see where you declared y or n. Those are variables, and you are treating them like literals. Just naming a variable y doesn't mean it represents the character 'y'. It be like saying int five; and expecting that variable to equal 5 just because of its name. It doesn't work that way. Variable names mean nothing to the computer. You want to use a literal 'y' and 'n':
if(ans == 'y') // <- note the apostrophes
- on line 35 you are using << with cin. You meant to use >>