Thread: Value returning function help

  1. #1
    Registered User Cpro's Avatar
    Join Date
    Oct 2006
    Posts
    149

    Value returning function help

    Hi,

    Code:
    #include <iostream>
    #include <string>
    #include <cmath>
    #include <fstream>
    #include <iomanip>
    
    using namespace std;
    
    int main()
    {
    	int OPTION= 99;
    	while(OPTION !=0 )
    	{
    		
            int MENU();			
    		int SIDE;
    		double AREAOFSQUARE;
    		OPTION=MENU();
    				
    		if (OPTION == 1)
    			{
    				cout<<"Enter the length of the side";
    				cin>>SIDE;
    				cout<<"The area of the square is: "<<AREAOFSQUARE(SIDE)<<endl;
    			}
    			else
    				cout<<"..."<<endl;
    	}
    	
    }
    int MENU()
    {
    	int CHOICE;
    	cout<<"1.)  Compute area of a square."<<endl;
    	cout<<"Select one."<<endl;
    	cin>>CHOICE;
    	return CHOICE;
    }
    double AREAOFSQUARE(double SIDE)
    {
    	return SIDE * SIDE;
    }
    for some reason the function "AREAOFSQUARE" is not being called correctly. it gives me this error: "error C2064: term does not evaluate to a function taking 1 arguements."
    I looked at examples in my book and the tutorials, but i can not find what i am doing wrong.

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Code:
    double AREAOFSQUARE;
    That's a variable. Compiler thinks you tried to use it as a function or something.

  3. #3
    Registered User Cpro's Avatar
    Join Date
    Oct 2006
    Posts
    149
    if i delete that part then it gives me these errors:

    error C3861: 'AREAOFSQUARE': identifier not found, even with argument-dependent lookup

    error C2365: 'AREAOFSQUARE' : redefinition; previous definition was a 'formerly unknown identifier'

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Function declarations needed. Either globally or locally to main.

    Code:
    int main()
    {
        int MENU(void);
        double AREAOFSQUARE(double);
    
    	int OPTION= 99;
    	while(OPTION !=0 )
    	{
    		int SIDE;
    		OPTION=MENU();
    				
    		if (OPTION == 1)
    			{
    				cout<<"Enter the length of the side";
    				cin>>SIDE;
    				cout<<"The area of the square is: "<<AREAOFSQUARE(SIDE)<<endl;
    			}
    			else
    				cout<<"..."<<endl;
    	}
    	
    }
    int MENU()
    {
    	int CHOICE;
    	cout<<"1.)  Compute area of a square."<<endl;
    	cout<<"Select one."<<endl;
    	cin>>CHOICE;
    	return CHOICE;
    }
    double AREAOFSQUARE(double SIDE)
    {
    	return SIDE * SIDE;
    }
    Code:
    #include <iostream>
    #include <string>
    #include <cmath>
    #include <fstream>
    #include <iomanip>
    
    using namespace std;
    
    double AREAOFSQUARE(double);
    int MENU(void);
    
    int main()
    {
    	int OPTION= 99;
    	while(OPTION !=0 )
    	{
    		int SIDE;
    		OPTION=MENU();
    				
    		if (OPTION == 1)
    			{
    				cout<<"Enter the length of the side";
    				cin>>SIDE;
    				cout<<"The area of the square is: "<<AREAOFSQUARE(SIDE)<<endl;
    			}
    			else
    				cout<<"..."<<endl;
    	}
    	
    }
    int MENU()
    {
    	int CHOICE;
    	cout<<"1.)  Compute area of a square."<<endl;
    	cout<<"Select one."<<endl;
    	cin>>CHOICE;
    	return CHOICE;
    }
    double AREAOFSQUARE(double SIDE)
    {
    	return SIDE * SIDE;
    }

  5. #5
    Registered User Cpro's Avatar
    Join Date
    Oct 2006
    Posts
    149
    Oh, i totally forgot about declaring them first. Thank you!

  6. #6
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I don't think uppercase functions and variables look good. I'd prefer only the first letter uppercase or the first letter of every word uppercase or totally lowercase.
    I only use uppercase names for macros.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem in returning value from the dll exported function
    By dattaforit in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2006, 04:30 AM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. returning pointers from a function
    By curlious in forum C++ Programming
    Replies: 2
    Last Post: 12-28-2003, 11:37 PM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM