0

I am writing a program that involves finding if a trapezoid is an isosceles triangle and every time I want the user to input info, it just skips over and returns. Help?

Console Debug

The code I have written here is below

#include <iostream>
#include "Quadrilateral.h"
#include "Trapezoid.h"
using namespace std;

int main() {

    Trapezoid T;
    T.setSides();

    cout << "Please enter the four sides, again!" << endl;
    double side1, side2, side3, side4;
    cin >> side1 >> side2 >> side3 >> side4;
    T.getSides(side1, side2, side3, side4);

    cout << "Computer the area of the trapezoid" << endl;
    double dblArea = T.Area(side1, side2, side3, side4, 1);
    cout << "The area is " << dblArea << " Square Units" << endl;

    cout << "Hello user, are you an isosceles trapezoid?" << endl;

    bool answer;
    int category{};
    cin >> answer;

    if (answer == true)
        category = 1;
    dblArea = T.Area(side1, side2, side3, side4, category);

    cout << "Please enter the 4 angles of a valid trapezoid";
    double angleA = 60, angleB = 60, angleC = 30, angleD = 30;
    cin >> angleA >> angleB >> angleC >> angleD;
    cout << "                  " << endl;
    //double angleA = 60, angleB = 60, angleC = 30, angleD = 30;
    
    if (angleA == angleB && angleC == angleD)
        cout << "This Trapezoid represents an isoceles triangle" << endl;

    return 0;
}

Code returns after cout << "Please enter the 4 angles of a valid trapezoid";

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Esther Lee
  • 25
  • 4
  • It doesn't `return`, but it might crash. Did you try in a debugger to see what's going on? – tadman Dec 12 '20 at 04:50
  • Why do you assign values to these angles, and then just squash them with inputs? Tip: Declare `std::vector` and `push_back` entries as you need them, for however many you might need. – tadman Dec 12 '20 at 04:50
  • 1
    Advice: clean up your code by fixing the indentation and adding braces around all your `if` statements. Then, you can reason more logically about your code and more easily find your bug(s). – costaparas Dec 12 '20 at 04:51
  • It's also worth noting that comparing floating point values of any kind to precise integer expectations is highly problematic due to the slight imprecision you may encounter. You might need to test that they're within a very small amount of that value, like `abs(angleA-angleB) < epislon` where `epsilon` is sufficiently small. – tadman Dec 12 '20 at 04:52
  • Yeah and I just get "The thread 0x37f8 has exited with code 0 (0x0). The thread 0x49c has exited with code 0 (0x0). The program '[17676] Lab 15 Project.exe' has exited with code 0 (0x0)." – Esther Lee Dec 12 '20 at 04:53
  • 2
    When reading `bool` values from `std::cin`, only `1` and `0` are allowed unless `std::boolalpha` is specified. See also [this answer](https://stackoverflow.com/a/26203585) for the similar problem. – heap underrun Dec 12 '20 at 04:56
  • can you share your entire code here, because this bit is working as intended on my system – Arsenic Dec 12 '20 at 04:56
  • 1
    That's a hard crash from doing something invalid. It's also a tip to drop this into your debugger and see precisely where that error occurs. – tadman Dec 12 '20 at 04:56
  • I added it here ^^ – Esther Lee Dec 12 '20 at 05:00
  • This code does not qualify as a [mre] since it relies on two header files that we do not have access to. (No, don't add that code to the question yet.) When I commented out the lines that depend on those header files, the code worked for me with whatever I felt like using as the input. Does the code work for you after commenting out the lines that use the variables `T` or `dblArea`? How many lines can you eliminate without getting rid of the problem? (Maybe the mystery header files are not really needed?) What input are you using? – JaMiT Dec 12 '20 at 05:48

0 Answers0