Results 1 to 6 of 6

Thread: i got an odd error in VC++ on a simple program, please help!

  1. #1

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    Question

    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!

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    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!
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3

    Thread Starter
    Registered User struntz's Avatar
    Join Date
    Aug 1999
    Location
    Brockway,Pa,USA
    Posts
    199

    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!

  4. #4
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    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;
    }
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  5. #5
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    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.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
  •  



Click Here to Expand Forum to Full Width