diff options
author | Michael Abed <michaelabed@gmail.com> | 2012-02-12 13:39:41 -0500 |
---|---|---|
committer | Michael Abed <michaelabed@gmail.com> | 2012-02-12 13:40:31 -0500 |
commit | bc7bfcecc63a071a11cf3565340464ba43d552cf (patch) | |
tree | fcb084511ed0dc7127f58d4e329882c94ea09dc3 | |
parent | 428682c33e9ca973f34d2c04acd8415caaf7fece (diff) | |
download | ec327-lab1-bc7bfcecc63a071a11cf3565340464ba43d552cf.tar.gz ec327-lab1-bc7bfcecc63a071a11cf3565340464ba43d552cf.tar.bz2 ec327-lab1-bc7bfcecc63a071a11cf3565340464ba43d552cf.zip |
write problem1
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | problem1.cpp | 50 |
2 files changed, 53 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57011a9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ + +*.un~ +*~ diff --git a/problem1.cpp b/problem1.cpp index e69de29..0e26609 100644 --- a/problem1.cpp +++ b/problem1.cpp @@ -0,0 +1,50 @@ + +#include <iostream> + +using namespace std; +int main() +{ + double t1b, t1h, t2b, t2h; // base and height of triangle 1 and 2 + cout << "Enter the information for the first triangle:" << endl; + + do { + cout << "Base: "; + cin >> t1b; + if (t1b - (int)t1b != 0 || t1b <= 0) + cout << "Please enter a positive integer" << endl; + } while (t1b <= 0 || t1b - (int)t1b != 0); + + do { + cout << "Height: "; + cin >> t1h; + if (t1h - (int)t1h != 0 || t1h <= 0) + cout << "Please enter a positive integer" << endl; + } while (t1h <= 0 || t1h - (int)t1h != 0); + + cout << "Second Triangle:" << endl; + + do { + cout << "Base: "; + cin >> t2b; + if (t2b - (int)t2b != 0 || t2b <= 0) + cout << "Please enter a positive integer" << endl; + } while (t2b <= 0 || t2b - (int)t2b != 0); + + do { + cout << "Height: "; + cin >> t2h; + if (t2h - (int)t2h != 0 || t2h <= 0) + cout << "Please enter a positive integer" << endl; + } while (t2h <= 0 || t2h - (int)t2h != 0); + + double area1 = 0.5 * t1h * t1b; + double area2 = 0.5 * t2h * t2b; + + if (area1 > area2) + cout << "Triangle 1 is bigger by " << area1-area2 << " units." << endl; + else if (area2 > area1) + cout << "Triangle 2 is bigger by " << area2-area1 << " units." << endl; + else + cout << "Triangle 1 and Triangle 2 are the same size" << endl; + return 0; +} |