Advertisement
ninepintcoggie

Zip code prob1

Feb 9th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. //the code should add all 5 digits of the code together, and then figure out how much to add to it to round to the nearest multiple of 10
  2. // the prof said you have done a brute force method of doing all 5 digits, but then wrapped it in a loop. The preferred method is to have a loop that is done once for each digit. Third, there is an error in your computation that can result in a check "digit" with the value 10 which of course requires 2 digits to express. Fourth, this function should not produce external output. The result is strictly the return value.
  3. int makeCheckDigit (int value)
  4. {
  5. int one, two, three, four, five, total, checkDigit, zipcode, count = 0;
  6.  
  7. do
  8. {
  9. five = zipcode % 10;
  10. four = (zipcode/10) % 10;
  11. three = (zipcode / 100) % 10;
  12. two = (zipcode / 1000) % 10;
  13. one = (zipcode / 10000) % 10;
  14. count += 1;
  15. }
  16.  
  17. while (count <= 5);
  18.  
  19. total = one + two + three + four + five;
  20. checkDigit = 10 - (total % 10);
  21.  
  22. return checkDigit;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement