Thread: need another pair of eyes please

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    9

    Smile need another pair of eyes please

    This code is suppose to change a binary into a deciaml. Could someone lend me there advice on the code.
    Code:
    do					
    {	remCheck = tmpVal%2;				tmpVal = tmpVal/2;								
                    if (remCheck != 0)
    	{	bitrepTmp[x] = 1;				}						else if (remCheck = 0)				{	bitrepTmp[x] = 0;				}											
                    x++;
    	if (tmpVal <= 0)
    	{	exit = 1;
    	}
    }while (exit != 1);

  2. #2
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Well, your formatting is atrocious which makes it hard to tell if your parenthesis and if statements are correct. Repost it again with only one statement per line and using indentation and code tags.

    One thing to think about though is that your binary number will come out backwards so you need to flip your array if you plan to do it this way.

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    1) Your indentation stinks (no offense).
    Code:
    do 
    {
       remCheck = tmpVal % 2;
       tmpVal = tmpVal / 2;
    
       if(remCheck != 0)
       {
          bitrepTmp[x] = 1;
       }
       else if(remCheck = 0)
       {
          bitrepTmp[x] = 0;
       }
    
       x++;
    
       if(tmpVal <= 0)
       {
          exit = 1;
       }
    }while(exit != 1);
    2) The else if marked in red is uneccessary. Since you tested remCheck != 0 and it failed it has to be 0. An else is enough.

    3) You compare with ==, not =. = is the assignment operator.

    4) It's more like a decimal -> binary conversion to me...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happier about helping you

    For example:

    Without code tags:

    for(int i=0;i<5;i++)
    {
    cout << "No code tags are bad";
    }

    With Code Tags:
    Code:
    for(int i=0;i<5;i++)
    {
         cout << "This code is easy to read";
    }
    This is of course a basic example...more complicated code is even easier to read with code tags than without.

    I've added code tags for you this time. They can be added by putting [code] at the beginning of your code and [/code] at the end. More information on code tags may be found on the code tag post at the top of every forum. I also suggest you take a look at the board guildlines if you have not done so already.

    This is a common first post mistake, just remember to use [code] tags in the future and you'll get much more help.

    If this is your first time posting here the welcome, and if there's anything I can do or any questions I can answer about these forums, or anything else, please feel free and welcome to PM me.


    Good Luck with your program,

    Kermi3
    Lead Moderator
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    9

    Smile RE POST OF MY CODE

    I am real sorry about the 'atrocious' formating. I don't usually put this much code into a question i have. I re-posted it for your convience.

    Code:
    do			
    {   remCheck = tmpVal%2;
          tmpVal = tmpVal/2;
          if (remCheck != 0)
         {     bitrepTmp[x] = 1;
         }					
         else if (remCheck = 0)
         {     bitrepTmp[x] = 0;
         }	
    
         x++;
         if (tmpVal <= 0)
         {    exit = 1;
         }
    }while (exit != 1);
    
    for (x=x-1; x>=0; x--)
    {     bitrep[y] = bitrepTmp[x];
           y++;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  2. Need an extra pair of eyes ....
    By Whoputthatthere in forum C Programming
    Replies: 5
    Last Post: 06-02-2006, 12:19 PM
  3. Writing my own stl container
    By curos in forum C++ Programming
    Replies: 10
    Last Post: 12-18-2005, 04:33 AM
  4. need a second pair of eyes to debug
    By RyeDunn in forum C Programming
    Replies: 7
    Last Post: 08-02-2002, 10:02 AM
  5. need a second pair of eyes
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 06-27-2002, 12:36 PM