help required urgent!!

This is a discussion on help required urgent!! within the C++ Programming forums, part of the General Programming Boards category; i want to print the double base representation of a number ie if my number is 38 i shud get ...

  1. #1
    ikj is offline
    Registered User
    Join Date
    May 2009

    Exclamation help required with my code on double base number representation !!urgent!!

    i want to print the double base representation of a number
    ie if my number is 38 i shud get 36 + 2 and for 655 i shud get 648 + 6 + 1.
    here's my code:

    unsigned long bs(unsigned long a[],unsigned long d, unsigned long beg, unsigned long end, unsigned long x)
         int mid;    
         if (x<a[mid])    
         else if(x<a[mid])    
         else if(x>a[end])
         {    cout<<a[end]<<" + ";  
               return a[end];   
         else if(x==a[mid])
              return a[mid];
    void alg(unsigned long a[],unsigned long d, unsigned long x)
         unsigned long num;
         if (num>0)
          int c,n,d;
          d=c=(unsigned long)(pow(32,2));
          unsigned long a[d],b[c],t,x,y;
          for(int i=0;i<32;i++)
              for(int j=0;j<32;j++)
                  b[c]=(unsigned long)(pow(2,i)*pow(3,j));
                  if(j==0 || ULONG_MAX/pow(3,j)>pow(2,i))
                    // cout<<i<<"\t"<<j<<"\t"<<a[d]<<endl;
         cout<<"enter element:";
         cout<<"its representation is :"<<endl;
    wat im doing in my code for alg() is im finding the element in the array using bs()
    if the elemnt i want is in the array im printing that otherwise im finding the element that is closest (from the lesser side) to it and finding the difference ie (x - closest number to x) and calling alg for the difference and so on.
    ie for 655 the closest elemnt is 648 and 655-648 is 7 , calling alg with 7 gives the closest elemnt as 6 n 7-6 is 1 n so on..
    in my bs() code im returning the elemnt or the one which is closest to it. but somehow its not printing that elemnt n neither is it returning it.

    please help...
    thanks for reading!
    Last edited by ikj; 05-28-2009 at 01:32 AM. Reason: more specific now

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Northern Virginia/Washington DC Metropolitan Area
    Welcome to the boards, that said...

    From the forum guidelines:
    Tips for Efficient and Successful Posting

    1. Don't use all caps.

    2. Use descriptive subject lines. Do not put URGENT!, or NEED HELP NOW, etc. in your title; it will not make people look at it any faster. Doing this makes many old time helpers on this board not look at the post at all.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    So what you're saying is that your bs function is broken. And if you look at it, you will quickly see that that is the case -- the base case must always be checked first.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  2. Urgent Help required.. pls help ??
    By intruder in forum Windows Programming
    Replies: 2
    Last Post: 01-10-2003, 01:05 PM
  3. Urgent help required
    By sweets in forum C++ Programming
    Replies: 3
    Last Post: 05-03-2002, 02:17 PM
  4. Urgent Solution Required
    By jamil_developer in forum C++ Programming
    Replies: 1
    Last Post: 03-09-2002, 02:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21