-
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!
-
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! :cool:
-
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!
-
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;
}
-
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.
-
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.