Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int input ();
- int difference (int, int);
- int calculateWrongAns (int);
- int main()
- {
- int num1;
- int num2;
- num1 = input();
- num2 = input();
- int actualAns = difference(num1, num2);
- int res = calculateWrongAns(actualAns);
- cout << res;
- return 0;
- }
- int input () {
- int x;
- cin >> x;
- return x;
- }
- int difference (int x, int y) {
- if (x > y) {
- return x - y;
- } else if (x < y) {
- return y - x;
- } else {
- return 0;
- }
- }
- int calculateWrongAns (int actualAns) {
- int lastNumber = actualAns % 10;
- int otherNumbers = actualAns / 10;
- int res;
- if (otherNumbers != 0) {
- res = (otherNumbers * 10) + (lastNumber == 1 ? 2 : lastNumber - 1);
- } else {
- res = lastNumber == 1 ? 2 : lastNumber - 1;
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement