Thread: compile problem

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    7

    compile problem

    I have a problem with this code ,can someone help.Thank you

    Code:
    #include <iostream>
    using namespace std;
    
    void main()
    {
        int number= get_number();
        int results=return_results();
    }
    int get_number()
    {
    	int num;
    	int temp_num=0;
    	int temp_num_pos=0;
    	int temp_num_neg=0;
    	int count=1;
    	while (count<=10)
        {
    	cout << "Enter a number" <<endl;
                    cin >> num ;
    	count++;
    	temp_num+=num;
    	
    	if(num>0)temp_num_pos+=num;
    	
    	if(num<0)temp_num_neg+=num;
    	
    	}
    }
    
    int return_results()
    {
        int temp_num=0;
        int temp_num_pos=0;
    	int temp_num_neg=0;
        cout <<"The sum of positive numbers is" << temp_num_pos<< endl;
        cout <<"The sum of negative numbers is" << temp_num_neg<< endl;
        cout <<"The sum of all numbers is" << temp_num<< endl;
    return 0;
    }
    Last edited by eriaug; 12-12-2004 at 11:35 AM.

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    1) You aren't using [code][/code] tags
    2) You are using void main()

    Fix those two points and I'll look at the rest.

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    a. Please use code tags. (See announcements at the top of the forum.)
    b. Please ask a specific question and give detail. What do you want it to do? Does it compile? What compiler errors do you get? Is it a runtime issue? What is it giving you and what do you expect? Etc.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  4. #4
    Registered User
    Join Date
    Nov 2004
    Posts
    7

    this are the errors

    cpp(6) : error C2065: 'get_number' : undeclared identifier
    cpp(7) : error C2065: 'return_results' : undeclared identifier
    cpp(10) : error C2373: 'get_number' : redefinition; different type modifiers
    cpp(31) : error C2373: 'return_results' : redefinition; different type modifiers
    Error executing cl.exe.

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    you need to prototype them:
    Code:
    #include <iostream>
    using namespace std;
    
    int get_number();
    int return_results();
    
    int main()

  6. #6
    Registered User
    Join Date
    Dec 2004
    Posts
    2
    first off try
    Code:
    get_number(number);
    instead of
    Code:
    int number= get_number();
    also
    like stated above
    Code:
    int get_number();
    int return_results();
    ill let you figure out the rest on your own
    both of them are wrong up there in int main();
    and both easy fixes

    look a noob that uses code tags
    Last edited by Sphearion; 12-12-2004 at 12:01 PM. Reason: missing pieces

  7. #7
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Quote Originally Posted by Sphearion
    first off try
    Code:
    get_number(number);
    instead of
    Code:
    int number= get_number();
    No, theres nothing wrong with that part of his code. His function get_number returns an int and takes no parameters, so what he has is correct. Is it supposed to return an int? Well, that I can't answer.

    However, there are some logic problems. The function get_number() is supposed to return an int but nothing is returned. Also, you'll need to look into scoping, because I'm guessing that you are thinking your temp values you calculate in get_number() will show up in return_results(), which is not true. Since they are declared in your first function, they will be destroyed when the function ends. Since you redeclare them in the second function, it will print the values as zero every time no matter what the user enters.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 09-14-2008, 02:35 PM
  2. compile problem
    By chintugavali in forum C++ Programming
    Replies: 3
    Last Post: 02-21-2008, 12:16 AM
  3. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  4. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  5. size of Object c++ compile problem
    By micha_mondeli in forum C++ Programming
    Replies: 5
    Last Post: 04-06-2005, 01:20 PM