Answer to Question #309584 in C++ for gabo

Question #309584


 

Intro Message:

 

This program tests if a triangle is valid by adding up the three angles.

 

Prompts and Input:

 

Enter the measurement of the first angle:   [user types: 50]

Enter the measurement of the second angle:  [user types: 100]

Enter the measurement of the third angle:   [user types: 30]

 

Output 1 (User types three numbers that DO add up to 180):

 

This is a valid triangle!

Would you like to run the program again (Y or N)? n

 

Output 2 (User types three numbers that do NOT add up to 180 and wants to try again):

 

This is an invalid triangle. Angles must add up to 180 degrees.

Would you like to run the program again (Y or N)? y

[* Repeat the Prompts and Input section *]


1
Expert's answer
2022-03-11T07:24:07-0500


#include <iostream>
#include <string>


using namespace std;


int main() {
	float angle1;
	float angle2;
	float angle3;
	string answer;
	cout<<"This program tests if a triangle is valid by adding up the three angles.\n\n";
	do{
		cout<<"Enter the measurement of the first angle: ";
		cin>>angle1;
		cout<<"Enter the measurement of the second angle: ";
		cin>>angle2;
		cout<<"Enter the measurement of the third angle: ";
		cin>>angle3;
		float sum=angle1+angle2+angle3;
		if(sum==180){
			cout<<"This is a valid triangle!\n\n";
		}else{
			cout<<"This is an invalid triangle. Angles must add up to 180 degrees.\n\n";
		}
		cout<<"Would you like to run the program again (Y or N)? ";
		cin.ignore();
		getline(cin,answer);
		
	}while(answer.compare("y")==0 || answer.compare("Y")==0);


	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment