User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 402,612 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,302 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 744 | Replies: 15 | Solved
Reply
Join Date: Jan 2008
Posts: 1,498
Reputation: VernonDozier is a jewel in the rough VernonDozier is a jewel in the rough VernonDozier is a jewel in the rough VernonDozier is a jewel in the rough 
Rep Power: 6
Solved Threads: 188
VernonDozier VernonDozier is offline Offline
Nearly a Posting Virtuoso

Re: beginner c++ programmer

  #11  
May 20th, 2008
Originally Posted by buddy1 View Post
I cannot change the function. Can anyone help me out.

Which function can't you change? What can you change? What input did you give the program? What should the output be? What is the actual output? You need to be more specific.
Reply With Quote  
Join Date: Mar 2008
Posts: 17
Reputation: buddy1 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
buddy1 buddy1 is offline Offline
Newbie Poster

Re: beginner c++ programmer

  #12  
May 21st, 2008
The c++ function void binaryAdd(int* sum, int& cBit, const int* bin1, const int* bin2 ) cannot be altered. I would be thankful for any help solving this problem.
Last edited by buddy1 : May 21st, 2008 at 5:06 pm.
Reply With Quote  
Join Date: Jan 2008
Posts: 1,498
Reputation: VernonDozier is a jewel in the rough VernonDozier is a jewel in the rough VernonDozier is a jewel in the rough VernonDozier is a jewel in the rough 
Rep Power: 6
Solved Threads: 188
VernonDozier VernonDozier is offline Offline
Nearly a Posting Virtuoso

Re: beginner c++ programmer

  #13  
May 21st, 2008
Originally Posted by buddy1 View Post
The c++ function void binaryAdd(int* sum, int& cBit, const int* bin1, const int* bin2 ) cannot be altered. I would be thankful for any help solving this problem.


You haven't described what the problem is. You've said you can't get it to run. See my former post for pertinent questions. Also, the prompts you use to ask for user input are not very descriptive. If you mean "Enter the ith binary digit", you should say that rather than "Enter i binary numbers". You aren't asking for numbers, you are asking for a single number, or rather a digit. Also, specify whether you want the user to enter the high order digits first or the low order bits first. You can't expect good output if the user doesn't know what to enter and in what order.
Reply With Quote  
Join Date: Apr 2008
Posts: 295
Reputation: tesuji is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 41
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: beginner c++ programmer

  #14  
May 22nd, 2008
Originally Posted by buddy1 View Post
The c++ function void binaryAdd(int* sum, int& cBit, const int* bin1, const int* bin2 ) cannot be altered. I would be thankful for any help solving this problem.


I am not that sure whether your question deals with my post #9, does it? Are there problems like how-to-change formal parameters of the function declaration or don't fit your actual parameters when calling this function? Are there any error messages?
Reply With Quote  
Join Date: Apr 2008
Posts: 295
Reputation: tesuji is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 41
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: beginner c++ programmer

  #15  
May 22nd, 2008
Originally Posted by buddy1 View Post
This is what I came up with. Still can't get it to run.

. . .
void binaryAdd( int* sum, int&cBit, const int* bin1, const int* bin2 )
{
       cBit = 0;
       int r;

       for ( int i = 0; i < 8; i++ )
       {
               r = bin1[i] + bin2[i] + cBit;
               if ( r % 2 == 0 ) sum[i] = 0;
               else sum[i] = 1;

               if ( r < 2 )
                       cBit = 0;

               else
                       cBit = 1;
       }
}


Possibly, you don't know what you should change in your function to get it function correctly. These are your problems in binaryAdd of posting #7:

1. Serious problem (where you begin when you are doing addition manually, left or right side?):
for ( int i = 0; i < 8; i++ ) --> for ( int i = 7; i >=0; i-- ) // see posting #9

2. better, for allowing continuous additions:
cBit = 0 --> should be set in main()

3. more beautiful:
if ( r % 2 == 0 ) sum[i] = 0;
else sum[i] = 1; --> sum[i] = r % 2;


krs,
tesu
Reply With Quote  
Join Date: Mar 2008
Posts: 17
Reputation: buddy1 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
buddy1 buddy1 is offline Offline
Newbie Poster

Re: beginner c++ programmer

  #16  
May 22nd, 2008
Thank for your help. You have been the most helpful person thus far. I will mark as solved

Kevin
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 12:41 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC