|
-
Apr 13th, 2001, 06:38 PM
#1
Thread Starter
Registered User
hello everyone, i'm new to C++, and i'm using VC++6.0 as the compiler, well here is the code...the error i get is this:
--------------------Configuration: Returning Mutli values - Win32 Debug--------------------
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Returning Mutli values.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Returning Mutli values.exe - 2 error(s), 0 warning(s)
------------------------------------------------------------------
here is my code: in math.h
Code:
#include <iostream.h>
#include "math.cpp"
//prototype
typedef unsigned short int USHORT;
USHORT factor(USHORT, USHORT*, USHORT*);
int main()
{
short question;
USHORT number, squared, cubed;
cout <<"Enter a number (0-20);
cin >> question;
//function
number = factor(number,squared,cubed);
if(number <= 20)
{
cout << "Number: " << "\n";
cout << "Squared: " << "\n";
cout << "Cubed: " << "\n";
{
else
cout <<"Error Number too big!" << endl;
}
}
return 0;
}
here is the code in math.cpp:
Code:
//math.cpp
//fucntion definition
typedef unsigned short int USHORT;
USHORT factor(USHORT n, USHORT*pSquared, USHORT*pCubed)
{
if (n > 20)
return 1; //failure, too big.
else
{
*pSquared = n*n;
*pCubed = n*n*n;
}
return 0; //success!
}
thanks for listening!
-
Apr 13th, 2001, 07:35 PM
#2
Frenzied Member
Make sure thet when you started your project you chose a win32 console application and not a win32 application. Your app is console and it seems that you are compiling it as a standard win32 app.
So, start a new project and choose console app. That is all!
-
Apr 13th, 2001, 10:27 PM
#3
Thread Starter
Registered User
still doen'st work....
i tried that, and thats not the problem, is there anything wrong with my code?
did i mix somthing up?
or forget a header? i can't figure it out!
-
Apr 14th, 2001, 04:44 AM
#4
Frenzied Member
This code works
Code:
#include <iostream.h>
//prototype
typedef unsigned short int USHORT;
USHORT Factor(USHORT, USHORT*, USHORT*);
int main()
{
short question;
USHORT number, squared, cubed;
cout <<"Enter a number (0-20)";
cin >> number;
short error;
error = Factor(number, &squared, &cubed);
if (!error)
{
cout << "Number: " <<number<< "\n";
cout << "Squared: " <<squared<< "\n";
cout << "Cubed: " <<cubed <<"\n";
}
else
{
cout <<"Error Number too big!" << endl;
}
return 0;
}
USHORT Factor(USHORT n, USHORT *pSquared, USHORT *pCubed)
{
USHORT Value = 0;
if (n > 20)
Value = 1;
else
{
*pSquared = n*n;
*pCubed = n*n*n;
Value = 0;
}
return Value;
}
-
Apr 14th, 2001, 04:47 AM
#5
Frenzied Member
Code:
if(number <= 20)
{
cout << "Number: " << "\n";
cout << "Squared: " << "\n";
cout << "Cubed: " << "\n";
{
In this code cout prints just the names number,squared... You should put the variables to be printed.
Code:
cout << "Number: " <<number<< "\n";
cout << "Squared: " <<squared<< "\n";
cout << "Cubed: " <<cubed <<"\n";
Also
Code:
cout <<"Enter a number (0-20);
cin >> question;
//function
number = factor(number,squared,cubed);
What role is question playing here. Nothing. You should have put it as the first argument of the function.
-
Apr 14th, 2001, 05:54 AM
#6
Monday Morning Lunatic
All your program code (IE main) needs to be in .cpp files. Definitions of function prototypes go in .h files. Make sure main is in a .cpp file.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|