Question

Using c++ specific methods:

Practice Problem 2 Write a program which obtains an integer w from the user. Assume that the user will always provide a posit

0 0
Add a comment Improve this question Transcribed image text
Answer #1

int w; cout << Enter value of w: ; clang version 7.8.9-3-ubuntu. 18.04.1 (tags/RELEASE 9 clang++-7 -pthread -o main main.cp

#include <iostream>
#include <cmath>


using namespace std;

int main() {
        int w;
        cout << "Enter value of w: ";
        cin >> w;

        while(w < 5) {
                cout << "Invalid value. Enter w again: ";
                cin >> w;
        }

        int x, y;
        bool found = false;
        cout << "Enter point x and y (separate by space): ";
        cin >> x >> y;

        if(x >= 0 && y >= 0 && (x + y) <= w) {
                cout << "The point is on or inside the upper triangle." << endl;
                found = true;
        }
        if(x <= 0 && y <= 0 && (abs(x) + abs(y)) <= w) {
                cout << "The point is on or inside the lower triangle." << endl;
                found = true;
        }

        if(!found) {
                cout << "The point is outside of the 2 triangles." << endl;
        }
}

please upvote. Thanks!

Add a comment
Know the answer?
Add Answer to:
Using c++ specific methods: Practice Problem 2 Write a program which obtains an integer w from the user. Assume that the user will always provide a positive number. The quantity w defines the followi...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT