So this is probably my first program ever basically. It takes user input about triangles then classifies them and outputs what kind of triangle the data given implies.I'm sorta guessing as I go along how things work just to play around with c++, but I've run into a problem. I'm not getting the intended results from my program (although they weren't perfect before) now instead of taking input for side lengths, I input the first side length and it automatically skips the other 2 side lengths and continues on with the code.
#include <iostream>
using std::cout;
using std::cin;
int sideA, sideB, sideC, angleA, angleB, angleC, longest, middle, shortest, sumbc, sumac, sumab;
int main()
{
cout << "Enter an angle for angle A\n";
cin >> angleA;
cout << "Enter an angle for angle B\n";
cin >> angleB;
cout << "Enter an angle for angle C\n";
cin >> angleC;
sumbc = angleB+angleC;
sumac = angleA+angleC;
sumab = angleA+angleB;
if(angleA + angleB + angleC == 180){ // This confirms that the angles add to 180 to form a triangle
cout << "This is a triangle!(Based on Angles)\n";
if(angleA == 90){ // These are for right angle triangles
cout << "This is a real right triangle!(angleA is 90 degrees..)\n";
cout << "Please enter the side lengths now\n";
cout << "Side 1:\n";
cin >> sideA;
cout << "Side 2:\n";
cin >> sideB;
cout << "Side 3:\n";
cin >> sideC;
if(sideA > sideB && sideA > sideC){
longest = sideA;
cout << "Side 1 is the hypotenuse!\n";
}
else if(sideB > sideA && sideB > sideC) {
cout << "Side 2 is the hypotenuse\n";
longest = sideB;
}
else if(sideC > sideA && sideC > sideB){
cout << "The hypotenuse is Side 3\n";
longest = sideC;
}
if(longest == sideC && sideA == sideB) { //Determines what kind of triangle it is if the longest side is sideC
cout << "This triangle is Right and Isosceles\n ";
}
else if(longest == sideB && sideC == sideA){
cout << "This triangle is Right and Isosceles\n ";
}
else if(longest == sideA && sideB == sideC ){
cout << "This triangle is Right and Isosceles\n ";
}
else {
cout << "This triangle is right and Scalene!\n";
}
}
if(angleB == 90){ // These are for right angle triangles
cout << "This is a real right triangle!(angleB is 90 degrees..)\n";
cout << "Please enter the side lengths now\n";
cout << "Side 1:\n";
cin >> sideA;
cout << "Side 2:\n";
cin >> sideB;
cout << "Side 3:\n";
cin >> sideC;
if(sideA > sideB && sideA > sideC){ //Finds longest side
longest = sideA;
cout << "Side 1 is the hypotenuse!\n";
}
else if(sideB > sideA && sideB > sideC) {
cout << "Side 2 is the hypotenuse\n";
longest = sideB;
}
else if(sideC > sideA && sideC > sideB){
cout << "The hypotenuse side is Side 3";
longest = sideC;
}
if(longest == sideC && sideA == sideB) { //Determines what kind of triangle it is if the longest side is sideC
cout << "This triangle is Right and Isosceles\n ";
}
else if(longest == sideB && sideC == sideA){
cout << "This triangle is Right and Isosceles\n ";
}
else if(longest == sideA && sideB == sideC ){
cout << "This triangle is Right and Isosceles\n ";
}
else {
cout << "This triangle is right and scalene!\n";
}
}
if(angleC == 90){ // These are for right angle triangles
cout << "This is a real right triangle!(angleC is 90 degrees..)\n";
cout << "Please enter the side lengths now\n";
cout << "Side 1:\n";
cin >> sideA;
cout << "Side 2:\n";
cin >> sideB;
cout << "Side 3:\n";
cin >> sideC;
if(sideA > sideB && sideA > sideC){
longest = sideA;
cout << "Side 1 is the hypotenuse!\n";
}
else if(sideB > sideA && sideB > sideC) {
cout << "Side 2 is the hypotenuse\n";
longest = sideB;
}
else if(sideC > sideA && sideC > sideB){
cout << "The hypotenuse is Side 3";
longest = sideC;
}
if(longest == sideC && sideA == sideB) { //Determines what kind of triangle it is if the longest side is sideC
cout << "This triangle is Right and Isosceles\n ";
}
else if(longest == sideB && sideC == sideA){
cout << "This triangle is Right and Isosceles\n ";
}
else if(longest == sideA && sideB == sideC ){
cout << "This triangle is Right and Isosceles\n ";
}
else {
cout << "This triangle is right and scalene!\n";
}
}
if(angleA == angleB && angleB == angleC){ // This is for equiangular/equilateral triangles
cout << "This is an equiangular/equilateral triangle.\n ";
cout << "Please enter the side lengths now\n";
cout << "Side 1:\n";
cin >> sideA;
int periequal = sideA*3;
int areaequal = sideA*sideA*.5;
cout << "The area is : " << areaequal << std::endl << "The perimeter is: " << periequal << std::endl;
cout << "This triangle is Isosceles, Equiangular, Equilateral, and Acute ";
}
if(angleA < 90 && sumbc != 120 && angleB < 90 && angleC < 90){ //deals with acute triangles
cout << "This is an acute triangle!\n";
cout << "Please enter the side lengths now\n";
cout << "Side 1:\n";
cin >> sideA;
cout << "Side 2:\n";
cin >> sideB;
cout << "Side 3:\n";
cin >> sideC;
int AcuteIsoPeri = sideA + sideB + sideC;
if (sideA == sideB){
cout << "This is an Acute, Isosceles Triangle. \n" << "With a perimeter of: " << AcuteIsoPeri;
}
else if(sideA == sideC){
cout << "This is an Acute, Isosceles Triangle. \n" << "With a perimeter of: " << AcuteIsoPeri;
}
else if(sideB == sideC){
cout << "This is an Acute, Isosceles Triangle. \n" << "With a perimeter of: " << AcuteIsoPeri;
}
else{
cout << "This is an Acute, Scalene Triangle. \n" << "With a perimeter of " << AcuteIsoPeri;
}
} //end of angleA if statement
if(angleA > 90){ //Deals with obtuse
cout << "This angle is Obtuse, angle A is greater than 90..";
cout << "Please enter the side lengths now\n";
cout << "Side 1:\n";
cin >> sideA;
cout << "Side 2:\n";
cin >> sideB;
cout << "Side 3:\n";
cin >> sideC;
if (sideA == sideB){
cout << "This is an Obtuse, Isosceles Triangle. \n";
}
else if(sideA == sideC){
cout << "This is an Obtuse, Isosceles Triangle. \n";
}
else if(sideB == sideC){
cout << "This is an Obtuse, Isosceles Triangle. \n";
}
else{
cout << "This is an Obtuse, Scalene Triangle. \n";
}
}
else if(angleB > 90){
cout << "This angle is Obtuse, angle B is greater than 90..";
cout << "Please enter the side lengths now\n";
cout << "Side 1:\n";
cin >> sideA;
cout << "Side 2:\n";
cin >> sideB;
cout << "Side 3:\n";
cin >> sideC;
if (sideA == sideB){
cout << "This is an Obtuse, Isosceles Triangle. \n";
}
else if(sideA == sideC){
cout << "This is an Obtuse, Isosceles Triangle. \n";
}
else if(sideB == sideC){
cout << "This is an Obtuse, Isosceles Triangle. \n";
}
else{
cout << "This is an Obtuse, Scalene Triangle. \n";
}
}
else if(angleC > 90){
cout << "This angle is Obtuse, angle C is greater than 90..";
cout << "Please enter the side lengths now\n";
cout << "Side 1:\n";
cin >> sideA;
cout << "Side 2:\n";
cin >> sideB;
cout << "Side 3:\n";
cin >> sideC;
if (sideA == sideB){
cout << "This is an Obtuse, Isosceles Triangle. \n";
}
else if(sideA == sideC){
cout << "This is an Obtuse, Isosceles Triangle. \n";
}
else if(sideB == sideC){
cout << "This is an Obtuse, Isosceles Triangle. \n";
}
else{
cout << "This is an Obtuse, Scalene Triangle. \n";
}
}
}
//scalene, obtuse, acute
return 0;
}
So I probably have no idea what I'm doing and I'm a terrible programmer or something haha, but here is what I get when I put in this information: Info: Angles are 40,114,26 ..it idetifies that it is obtuse which is right, then it asks for the side lengths which is also what I intended for it to do.. Then I put in the first side length(6.4) and the program skips to the end once I press enter. I probably made a syntax error that I can't find, or the way I used if statements is plain wrong. If you can help with this mess that would be much appreciated! (Started researching c++ the other night and wanted to apply it to something real which is how this monster was created..)Examle of Proper Output... Example of Wrong Output
Aucun commentaire:
Enregistrer un commentaire