Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- int main()
- {
- double x, y;
- cout << "enter x:" << endl;
- cin >> x;
- if (x <= 0) {
- y = -1 * x;
- cout << y << endl;
- }
- else if ((x > 0) && (x <= 1)) {
- y = x;
- cout << y << endl;
- if ((y < 0) && (y > 1)) {
- cout << "out of range:" << endl;
- }
- }
- else if ((x > 1) && (x <= 2)) {
- y = 1;
- cout << y << endl;
- }
- else if ((x > 2) && (x <= 3)) {
- y = -0.5 * (x);
- if ((y >= 1) && (y <= -1))
- cout << "out of range" << endl;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement