Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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
- // 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.
- int makeCheckDigit (int value)
- {
- int one, two, three, four, five, total, checkDigit, zipcode, count = 0;
- do
- {
- five = zipcode % 10;
- four = (zipcode/10) % 10;
- three = (zipcode / 100) % 10;
- two = (zipcode / 1000) % 10;
- one = (zipcode / 10000) % 10;
- count += 1;
- }
- while (count <= 5);
- total = one + two + three + four + five;
- checkDigit = 10 - (total % 10);
- return checkDigit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement