Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int number;
- cin >> number;
- double bonus = 0;
- if (number <= 100) {
- bonus = 5;
- }
- else if (number > 1000) {
- bonus = number * 0.1;
- }
- else {
- bonus = number * 0.2;
- }
- if (number % 2 == 0) {
- bonus++;
- }
- else if (number % 10 == 5) {
- bonus += 2;
- }
- cout << bonus << endl;
- cout << bonus + number << endl;
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- using namespace std;
- int main() {
- int number;
- cin >> number;
- double bonus = 0;
- bonus +=
- number <= 100 ? 5 :
- number > 1000 ? number * 0.1 : number * 0.2;
- bonus +=
- number % 2 == 0 ? 1 :
- number % 10 == 5 ? 2 : 0;
- cout << bonus << endl << bonus + number << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement