Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main()
- {
- const int max3digit{ 999 };
- const int min5digit{ 10000 };
- // enum Pos is like four constants packed together under one roof
- // It simply replaces
- // const int one {1};
- // const int two {10};
- // const int three {100};
- // const int four {1000};
- enum Pos { one = 1, two = 10, three = 100, four = 1000 };
- int num{ 1234 };
- int res{ 0 };
- std::cout << "Enter four digit number\n";
- std::cin >> num;
- if (num > max3digit and num < min5digit)
- {
- res += (num % 10) * Pos::two;
- num /= 10;
- res += (num % 10) * Pos::one;
- num /= 10;
- res += (num % 10) * Pos::four;
- num /= 10;
- res += (num % 10) * Pos::three;
- std::cout << "Changed digits: " << res << '\n';
- }
- else
- {
- std::cout << "Not a four digit number!\n";
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment