Problem with C++ please help
One day I decided what i am going to do for a living.Be a programmer and create games.So why not start from now I said to myself.Then I bought Tricks of the windows game programming Gurus(big mistake)I didn''t even know how to write in C++.Then I bought a book gor C++ named Learn C++ in 10 minutes.It is really good but I have creaye a program which doesn''t work and I don''t know why?It says it has a link error.?!I am going to show it to you in case you know anything nad can help me.
#include <iostream.h>
int main()
{
int firstNumber, secondNumber;
cout << "Enter two numbers.\nFirst: ";
cin >> firstNumber;
cout << "\nSecond: ";
cin >> secondNumber;
cout << "\n\n";
if (firstNumber >= secondNumber)
{
if ( (firstNumber % secondNumber) == 0)
{
if (firstNumber == secondNumber)
cout << "They are the same!\n";
else
cout << "They are evenly divisible!\n";
}
else
cout << "They are not evenly divisible!\n";
}
else
cout << "Hey! the second one is larger!\n";
return 0
}
When you see a roller coaster, get on it,put your hands in the air,and ride it to the very end.Life doesn't remember you unless you kick,scream,and claw your way to the top.There is nothing in the world that is impossible.If you believe that you can do it, you will.
The thing that strikes me the most is that you''re missing a semicolon at the line: return 0
-=Lohrno
-=Lohrno
Post your link error here, so we have a better clue as to what might be wrong.
It's not what you're taught, it's what you learn.
quote: Original post by Landsknecht
Think it might have something to do with the fact that firstNumber and secondNumber are never declared? Gotta declare your variables before you use them!
Landsknecht
Yeah he does, its the first line in his main function. He doesnt have to initialize them either as he gets them imediately. (Although its good programming practice to always initialize your variables.
-=Lohrno
hmm did you save project as the same file name as the cpp file??? and did you save them in the same folder...
when i get a linker error at school usually that means that i just clicked save and forgot to click save project... cuse you have to save both... now thats only with my school c++ compiler... cuse my one at home you only need to save the cpp file...
if your compiler does need a project file along with the cpp to compile make sure your project file is in the same place as your cpp thingy... cuse its trying to link them but cant
just so you know iam a beginer also so i dont know what iam talking about but i have gotten that error and i beleive my problem is the same as yours
when i get a linker error at school usually that means that i just clicked save and forgot to click save project... cuse you have to save both... now thats only with my school c++ compiler... cuse my one at home you only need to save the cpp file...
if your compiler does need a project file along with the cpp to compile make sure your project file is in the same place as your cpp thingy... cuse its trying to link them but cant
just so you know iam a beginer also so i dont know what iam talking about but i have gotten that error and i beleive my problem is the same as yours
1. What compiler are you using, what version?
2. What's the (exact) error message you get?
The code you posted doesn't compile because of a missing ';', the code has to be compiled before it can be linked, so are you sure it's a linker error you get?
btw:
iostream.h is an old header, you should replace the line:
#include <iostream.h>
with:
#include <iostream>
using namespace std;
This should work unless your compiler is really old, in which case you better look for a more recent compiler.
[edited by - kvh on March 14, 2002 6:37:27 AM]
2. What's the (exact) error message you get?
The code you posted doesn't compile because of a missing ';', the code has to be compiled before it can be linked, so are you sure it's a linker error you get?
btw:
iostream.h is an old header, you should replace the line:
#include <iostream.h>
with:
#include <iostream>
using namespace std;
This should work unless your compiler is really old, in which case you better look for a more recent compiler.
[edited by - kvh on March 14, 2002 6:37:27 AM]
I use VC++ 6.0 introductory edition.
The error I get is:
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/if statement.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
if statement.exe - 2 error(s), 0 warning(s)
Help me please....
The error I get is:
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/if statement.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
if statement.exe - 2 error(s), 0 warning(s)
Help me please....
When you see a roller coaster, get on it,put your hands in the air,and ride it to the very end.Life doesn't remember you unless you kick,scream,and claw your way to the top.There is nothing in the world that is impossible.If you believe that you can do it, you will.
Also the semicolon was right I don''t know why it wasn''t posted my problem is the linking error I have above.
When you see a roller coaster, get on it,put your hands in the air,and ride it to the very end.Life doesn't remember you unless you kick,scream,and claw your way to the top.There is nothing in the world that is impossible.If you believe that you can do it, you will.
You are trying to make a windows application when you should be making a console application.
March 14, 2002 07:26 AM
Because you''re using Visual C/C++ and you created a Win32 Executable instead of a Console App like you wanted to. Re-Make the project, and set it to be a console app instead of a Win32 executable. This will solve your problem. With Win32, you have a WinMain instead of a main.
Billy - BillyB@mrsnj.com
Billy - BillyB@mrsnj.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement