•
•
•
•
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
![]() |
•
•
Join Date: Jan 2008
Posts: 1,498
Reputation:
Rep Power: 6
Solved Threads: 188
•
•
•
•
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.
•
•
Join Date: Apr 2008
Posts: 295
Reputation:
Rep Power: 1
Solved Threads: 41
•
•
•
•
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?
•
•
Join Date: Apr 2008
Posts: 295
Reputation:
Rep Power: 1
Solved Threads: 41
•
•
•
•
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
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- declaration syntax error? (C++)
- Need help setting up graphics (C++)
- Beginner programmer (C++)
- Can't Get Going with eVC++4.0 (C++)
Other Threads in the C++ Forum
- Previous Thread: Elementary Class/const Question
- Next Thread: Compile error for RTTI



Linear Mode