Thread: Problem running recursive program!

  1. #1
    Registered User
    Join Date
    Dec 2010
    Location
    Delhi, India
    Posts
    59

    Problem running recursive program!

    I am trying to run the recursive program for the rod cutting problem. My code compiles but fails to build. I am using MS Visual Studio 2010, here's the code:

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    #define MAX(a,b) ((a)> (b) ? (a) :(b))
    
    int max_revenue (int *price, int length)
    {
    	int q , i;
    	if (length == 0)
    		return 0;
    	q = -1;
    	for (i = 1; i <=length; i++)
    	{
    		q = MAX(q, (price[i-1] + max_revenue(price, length-i)));
    	}
    	return q;
    }
    
    int main()
    {
    	int *price;
    	int max_price;	
    	price = (int *)malloc(4*sizeof(int));
    	price[0] = 1;
    	price[1] = 5;
    	price[2] = 8;
    	price[3] = 9;
    	
    	max_price = max_revenue (price, 4);
    	return 0;
    }
    I get an error- unresolved externals. Please help!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Dunno - you'll have to post your actual error messages, because it compiles OK here.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Location
    Delhi, India
    Posts
    59
    I can't even tell you what the mistake was, such a silly mistake , I accidentally made a WinMain project so it was expecting a WinMain function instead of int main, it runs easily now, wasted almost an hour on it. Thanks for your reply

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-21-2011, 02:43 AM
  2. Replies: 5
    Last Post: 03-21-2011, 02:17 AM
  3. Keep running program and 'int' problem
    By willrs2 in forum C++ Programming
    Replies: 21
    Last Post: 02-10-2008, 11:22 AM
  4. Problem running program
    By JOCAAN in forum C++ Programming
    Replies: 3
    Last Post: 10-19-2007, 04:09 PM
  5. Running Program Problem
    By warfang in forum C++ Programming
    Replies: 10
    Last Post: 03-28-2007, 02:02 PM