Dividing the length by sin(x) always results in a negative answer - c++

#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int main()
{
int caltype;
int numorden;
int length, angle;
cout << "Type '1' for sine, '2' for cosine and '3' for tangent." << endl;
cin >> caltype;
switch (caltype) {
case 1:
cout << "Is the unknown length the numerator or the denominator? Type '1' for numerator and '2' for denominator." << endl;
cin >> numorden;
switch (numorden) {
case 1:
cout << "Type the length of the hypotenuse." << endl;
cin >> length;
cout << "Type in the angle." << endl;
cin >> angle;
cout << "sinangle = O/H" << endl;
cout << "sin" << angle << " = x/" << length << endl;
cout << length << "sin" << angle << " = x" << endl;
cout << "Therefore x = " << length *sin (angle);
break;
case 2:
cout << "Type the length of the opposite." << endl;
cin >> length;
cout << "Type in the angle." << endl;
cin >> angle;
cout << "sinangle = O/H" << endl;
cout << "sin" << angle << " = " << length << "/x" << endl;
cout << "xsin" << angle << " = " << length << endl;
cout << "Therefore x = " << length / sin (angle);
}
}
}
What I am making right now is a program that will show you the steps when it is doing trigonometry. For some reason, when the opposite is divided by, lets say, sin(30), it always results in a negative number. Why is that? The error appears to be occurring at this line:
cout << "Therefore x = " << length / sin (angle);

You need to convert it to radians:
sin (angle * PI/180);
UPDATE:
What is PI?
World Record values of PI

The sin function takes input as radian:
sin (angle * M_PI/180);
where M_PI = 3.141...., which is a constant.

Related

Visual Studios Issue where only first section is being displayed

I am having some troubles where my code is only displaying the first section I have inputed "Sphere" and is not letting me input any other values when I go to Debug.
The basis of the code is to have the user choose a selction, and be able to input values to find the surface areas and volumes of a shape. Below is my code. (Also I am new to this so if there are any pointers I would greatly appreciate it!)
This is for an exam I have so just some input as to where I am going wrong would be great. I want to learn it not have the whole thing completed for me
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
int main()
{
//Text
cout << "\nHello there! This program will help " << endl;
cout << "\ncalulate the surface areas and the " << endl;
cout << "\nvolumes of the displayed shapes below." << endl;
cout << endl;
cout << "----------------------------------------" << endl;
cout << " A: Sphere " << endl;
cout << " B: Cube " << endl;
cout << " C: Dodecahedron " << endl;
cout << " D: Cylinder " << endl;
cout << " E: Cone " << endl;
cout << "----------------------------------------" << endl;
cout << endl;
//Variables
double Sphere = 0.0,
Cube = 0.0,
Dodecahedron = 0.0,
Cylinder = 0.0,
Cone = 0.0;
float A = (Sphere),
B = (Cube),
C = (Dodecahedron),
D = (Cylinder),
E = (Cone);
//Question
enter code here
cout << "Please select one of the following..." << endl;
cin >> A;
cin >> B;
cin >> C;
cin >> D;
cin >> E;
{
//Sphere
int SphereRadius = 0.0;
double pi = 3.1415926535898;
double SphereSA = (4 * pi * (SphereRadius * SphereRadius));
double SphereV = ((int(4 / 3)) * (pi * (SphereRadius * SphereRadius * SphereRadius)));
if (Sphere);
cout << "\nIn order to find the surface area and " << endl;
cout << "\nvolume we will need a radius. " << endl;
cout << endl;
cout << "\nPlease input a positive number for the radius: " << endl;
cin >> SphereRadius;
cout << endl;
cout << "\nWith the given radius... " << endl;
cout << endl;
cout << "\nSurface area will be: " << setprecision(2) << SphereSA << endl;
cout << endl;
cout << "\nVolume will be: " << setprecision(2) << SphereRadius << endl;
}
{
//Cube
int CubeSide = 0.0;
double CubeSA = (6 * (CubeSide * CubeSide));
double CubeV = (CubeSide * CubeSide * CubeSide);
if (Cube);
cout << "\nIn order to find the surface area and " << endl;
cout << "\nvolume we will need a side length. " << endl;
cout << endl;
cout << "\nPlease input a positive number for the side length: " << endl;
cin >> CubeSide;
cout << endl;
cout << "\nWith the given side length... " << endl;
cout << endl;
cout << "\nSurface area will be: " << setprecision(2) << CubeSA << endl;
cout << endl;
cout << "\nVolume will be: " << setprecision(2) << CubeV << endl;
cout << endl;
}
{
//Cone
int ConeH = 0.0;
double ConeR = 0.0;
double ConeSA = (pi * ConeR * (ConeR + sqrt((ConeH * ConeH) + (ConeR * ConeR))));
double ConeV = (pi * ((ConeR * ConeR) * (ConeH / 3)));
if (Cone);
cout << "\nIn order to find the surface area and " << endl;
cout << "\nvolume we will need a radius and a height. " << endl;
cout << endl;
cout << "\nPlease input a positive number for the radius: " << endl;
cin >> ConeR;
cout << endl;
cout << "\nPlease input a positive number for the height: " << endl;
cin >> ConeH;
cout << endl;
cout << "\nWith the given side length... " << endl;
cout << endl;
cout << "\nSurface area will be: " << setprecision(2) << ConeSA << endl;
cout << endl;
cout << "\nVolume will be: " << setprecision(2) << ConeV << endl;
cout << endl;
}
{
//Dodecahedron
int DodeEdge = 0.0;
double DodeSA = (3 * (sqrt(25 + 10 * sqrt(5) * DodeEdge)));
double DodeV = (DodeEdge * ((15 + (7 * sqrt(5)) / 4)));
if (Dodecahedron);
cout << "\nIn order to find the surface area and " << endl;
cout << "\nvolume we will need to have an edge. " << endl;
cout << endl;
cout << "\nPlease input a positive number for the edge: " << endl;
cin >> DodeEdge;
string DodeEdge;
cout << "\nWith the given edge length... " << endl;
cout << endl;
cout << "\nSurface area will be: " << setprecision(2) << DodeSA << endl;
cout << endl;
cout << "\nVolume will be: " << setprecision(2) << DodeV << endl;
cout << endl;
}
{
//Cylinder
int CylinderH = 0.0;
int CylinderR = 0.0;
double CylinderSA = ((2 * CylinderR * pi * CylinderH) + (2 * pi * (CylinderR * CylinderR)));
double CylinderV = (pi * (CylinderR * CylinderR) * CylinderH);
if (Cylinder);
cout << "\nIn order to find the surface area and " << endl;
cout << "\nvolume we will need to have a radius and a height. " << endl;
cout << endl;
cout << "\nPlease input a positive number for the radius: " << endl;
cin >> CylinderR;
cout << endl;
cout << "\nPlease input a positive number for the height: " << endl;
cin >> CylinderH;
cout << endl;
cout << "\nWith the given radius and height... " << endl;
cout << endl;
cout << "\nSurface area will be: " << setprecision(2) << CylinderSA << endl;
cout << endl;
cout << "\nVolume will be: " << setprecision(2) << CylinderV << endl;
cout << endl;
}
return 0;
}
The error is that the code order is not correct:
int SphereRadius = 0.0;
double pi = 3.1415926535898;
double SphereSA = (4 * pi * (SphereRadius * SphereRadius));
double SphereV = ((int(4 / 3)) * (pi * (SphereRadius * SphereRadius * SphereRadius)));
cout << "\nPlease input a positive number for the radius: " << endl;
cin >> SphereRadius;
I modified code by using switch-case:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#define Sphere 1
#define Cube 2
#define Dodecahedron 3
#define Cylinder 4
#define Cone 5
using namespace std;
double pi = 3.1415926535898;
int main()
{
//Text
cout << "\nHello there! This program will help " << endl;
cout << "\ncalulate the surface areas and the " << endl;
cout << "\nvolumes of the displayed shapes below." << endl;
cout << endl;
cout << "----------------------------------------" << endl;
cout << " 1: Sphere " << endl;
cout << " 2: Cube " << endl;
cout << " 3: Dodecahedron " << endl;
cout << " 4: Cylinder " << endl;
cout << " 5: Cone " << endl;
cout << "----------------------------------------" << endl;
cout << endl;
cout << "Please select one of the following..." << endl;
//Variables
int UserSelect = 0;
cin >> UserSelect;
while (UserSelect < 1 || UserSelect>5)
{
cout << "Please select the right option" << endl;
cin >> UserSelect;
cout << endl;
}
switch (UserSelect)
{
case Sphere:
{
//Sphere
int SphereRadius = 0.0;
cout << "\nIn order to find the surface area and " << endl;
cout << "\nvolume we will need a radius. " << endl;
cout << endl;
cout << "\nPlease input a positive number for the radius: " << endl;
cin >> SphereRadius;
cout << endl;
double SphereSA = (4 * pi * (SphereRadius * SphereRadius));
double SphereV = ((int(4 / 3)) * (pi * (SphereRadius * SphereRadius * SphereRadius)));
cout << "\nWith the given radius... " << endl;
cout << endl;
cout << "\nSurface area will be: " << setprecision(2) << SphereSA << endl;
cout << endl;
cout << "\nVolume will be: " << setprecision(2) << SphereRadius << endl;
}
break;
case Cube:
{
//Cube
int CubeSide = 0.0;
cout << "\nIn order to find the surface area and " << endl;
cout << "\nvolume we will need a side length. " << endl;
cout << endl;
cout << "\nPlease input a positive number for the side length: " << endl;
cin >> CubeSide;
cout << endl;
double CubeSA = (6 * (CubeSide * CubeSide));
double CubeV = (CubeSide * CubeSide * CubeSide);
cout << "\nWith the given side length... " << endl;
cout << endl;
cout << "\nSurface area will be: " << setprecision(2) << CubeSA << endl;
cout << endl;
cout << "\nVolume will be: " << setprecision(2) << CubeV << endl;
cout << endl;
}
break;
case Dodecahedron:
{
//Dodecahedron
int DodeEdge = 0.0;
cout << "\nIn order to find the surface area and " << endl;
cout << "\nvolume we will need to have an edge. " << endl;
cout << endl;
cout << "\nPlease input a positive number for the edge: " << endl;
cin >> DodeEdge;
double DodeSA = (3 * (sqrt(25 + 10 * sqrt(5) * DodeEdge)));
double DodeV = (DodeEdge * ((15 + (7 * sqrt(5)) / 4)));
//string DodeEdge;
cout << "\nWith the given edge length... " << endl;
cout << endl;
cout << "\nSurface area will be: " << setprecision(2) << DodeSA << endl;
cout << endl;
cout << "\nVolume will be: " << setprecision(2) << DodeV << endl;
cout << endl;
}
break;
case Cylinder:
{
//Cylinder
int CylinderH = 0.0;
int CylinderR = 0.0;
cout << "\nIn order to find the surface area and " << endl;
cout << "\nvolume we will need to have a radius and a height. " << endl;
cout << endl;
cout << "\nPlease input a positive number for the radius: " << endl;
cin >> CylinderR;
cout << endl;
cout << "\nPlease input a positive number for the height: " << endl;
cin >> CylinderH;
cout << endl;
double CylinderSA = ((2 * CylinderR * pi * CylinderH) + (2 * pi * (CylinderR * CylinderR)));
double CylinderV = (pi * (CylinderR * CylinderR) * CylinderH);
cout << "\nWith the given radius and height... " << endl;
cout << endl;
cout << "\nSurface area will be: " << setprecision(2) << CylinderSA << endl;
cout << endl;
cout << "\nVolume will be: " << setprecision(2) << CylinderV << endl;
cout << endl;
}
break;
case Cone:
{
//Cone
int ConeH = 0.0;
double ConeR = 0.0;
cout << "\nIn order to find the surface area and " << endl;
cout << "\nvolume we will need a radius and a height. " << endl;
cout << endl;
cout << "\nPlease input a positive number for the radius: " << endl;
cin >> ConeR;
cout << endl;
cout << "\nPlease input a positive number for the height: " << endl;
cin >> ConeH;
cout << endl;
double ConeSA = (pi * ConeR * (ConeR + sqrt((ConeH * ConeH) + (ConeR * ConeR))));
double ConeV = (pi * ((ConeR * ConeR) * (ConeH / 3)));
cout << "\nWith the given side length... " << endl;
cout << endl;
cout << "\nSurface area will be: " << setprecision(2) << ConeSA << endl;
cout << endl;
cout << "\nVolume will be: " << setprecision(2) << ConeV << endl;
cout << endl;
}
break;
default:
break;
}
return 0;
}

Incorrect user input

Trying to let only numbers be a vaild input for a quadratic equation solver. I used bool and broke my code and no matter the input it just gives me my error message even if it is a vaild input.
After the progarm ask you to confirm the coefficients are correct, even if you put Y you get the " Please input a number. Please try again". how do you fix this?
I added the bool becasue that what my teacher showed me to use for checking inputs, very new to c++ and coding. I just added the whole code, the HW was to update HW 5 to do a few things more. I broke it trying to check inputs, when adding bool.
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main()
{
string first, last;
double a, b, c, x1, x2, discriminant, realpart, imaginarypart;
char ch;
cout << "Please enter First and Last name," << endl;
cout << " " << endl;
cout << "First Name= ";
cin >> first;
cout << "and" << endl;
cout << "Last Name=";
cin >> last;
cout << " " << endl;
cout << " Hello " << first << " " << last << " "
<< "welcome." << endl;
cout << " " << endl;
bool isCorrect{ true };
do {
start:
isCorrect = true;
cout << "Enter the coefficients of a: ";
cin >> a;
cout << " " << endl;
cout << "Enter the coefficients of b: ";
cin >> b;
cout << " " << endl;
cout << "Enter the coefficient of c: ";
cin >> c;
cout << " " << endl;
cout << " A = " << a;
cout << " B = " << b;
cout << " C = " << c << endl
<< endl;
cout << " Confirm the coefficients value are correct or not (y/n): " << endl;
cout << " " << endl;
cin >> ch;
if (ch == 'n' || ch == 'N')
goto start;
cout << " " << endl;
discriminant = b * b - 4.0 * a * c;
if (cin.fail())
;
{
isCorrect = false;
cin.clear();
cin.ignore(245, '\n');
cout << " Please input a number. Please try again" << endl;
}
} while (!isCorrect);
bool isExit(false);
if (a == 0) {
cout << " " << endl;
cout << "Error message: a can not = zero (0) " << endl;
}
else if (discriminant > 0) {
x1 = (-b + sqrt(discriminant)) / (2.0 * a);
x2 = (-b - sqrt(discriminant)) / (2.0 * a);
cout << "Roots are real and different." << endl;
cout << " " << endl;
cout << "x1 = " << x1 << endl;
cout << "x2 =" << x2 << endl;
}
else if (discriminant == 0) {
cout << "Roots are real and same." << endl;
cout << " " << endl;
x1 = -b / (2.0 * a);
cout << "x1 = x2 ="
" "
<< x1 << endl;
}
else {
//cout << "Error message: No real solution exist." << endl; // Part 1 error code for no real solutions
realpart = -b / (2.0 * a); //Code for part 2
imaginarypart = sqrt(-discriminant) / (2.0 * a); // Code for part 2
cout << "Roots are complex and different." << endl; // Code for part 2
cout << " " << endl;
cout << "x1 = " << realpart << "+" << imaginarypart << "i" << endl; // Code for part 2
cout << "x2 = " << realpart << "-" << imaginarypart << "i" << endl; // Code for part 2
}
cout << " " << endl;
cout << " Would you like to solve another quadratic equation (y/n): " << endl;
cin >> ch;
if (ch == 'y' || ch == 'Y')
goto start;
else
(ch == 'n' || ch == 'N');
return 0;
}

Variable not declared in scope and a defined function cannot be used as a function

This is how the code currently looks like.
#include <iostream>
#include <iomanip>
using namespace std;
int cos(angle)
{
float rad = angle;
float radPh = 1;
float facto = 1;
float tOld = 1;
float tNew = 0;
float tPh = 1;
float tDiff = 1;
float cosAns;
precision = precision + 1;
float x = 10;
float finalPr = 1;
for (int counter = 0; counter < precision; ++counter)
{
finalPr /= x;
}
finalPr = 0.5 * finalPr;
while (tDiff > finalPr)
{
tOld = tPh;
tNew = ((-1)*tOld*rad*rad)/((facto+1)*(facto+2));
tPh = tNew;
radPh = tNew;
facto = facto + 2;
tDiff = tOld - tNew;
cosAns = radPh;
}
return cosAns;
}
int main()
{
int precision = 10;
int choice;
//Title and Menu
cout << endl << "==============" << endl << " TRIGONOMETRY " << endl << "==============";
cout << endl << endl << "Current Precision: " << precision;
cout << endl << "Select:";
cout << endl << "1. Change Decimal Precision";
cout << endl << "2. Calculate Cos and Sin";
cout << endl << "9. Exit";
while (true)
{
//User Prompt
cout << endl << endl << "Please enter your choice. => ";
cin >> choice;
if (choice == 1)
{
cout << endl << "Please enter a value between 2 and 10. => ";
cin >> precision;
cout << "Current precision is " << precision;
}
if (choice == 2)
{
float angle, anglePh;
float pi = 3.14159265358979323846264338327950288419716;
char angleType;
cout << endl << "Please enter an angle. => ";
cin >> angle;
cout << endl << "Is the angle in degrees or in radian?";
cout << endl << "Input D if it's in degrees,";
cout << endl << "Input R if it's in radian. => ";
cin >> angleType;
if (angleType == 'D')
{
anglePh = angle;
angle = angle*pi/180;
cout << anglePh << " degrees = " << angle << " radian";
}
cout << endl << "Calculating Cos...";
cos(angle);
cout << endl << "Calculating Sin...";
}
if (choice == 9)
{
break;
}
}
}
I am building a program that gets the angle from the user and then convert it into radian before calculating its Sine and Cosine values. When I run this code it tells me that the angle from "int cos(angle)" was not defined, so I tried moving it into the if loop for choice 2, but it didn't solve the issue. It also says that cos(angle) cannot be used as a function when I tried to trigger it from the if loop for choice 2. Any ideas on this?
I actually made a similar program using Python back then, and this method that I used to write the program worked. I know there are some differences between Python and C++, but I thought the general idea would still apply.
Thanks in advance.
Cheers.
In the function definition/declaration you must mention the argument data type.
int cos(float angle, int precision)
#include <iostream>
#include <iomanip>
using namespace std;
int cos(float angle, int precision)
{
float rad = angle;
float radPh = 1;
float facto = 1;
float tOld = 1;
float tNew = 0;
float tPh = 1;
float tDiff = 1;
float cosAns;
precision = precision + 1;
float x = 10;
float finalPr = 1;
for (int counter = 0; counter < precision; ++counter)
{
finalPr /= x;
}
finalPr = 0.5 * finalPr;
while (tDiff > finalPr)
{
tOld = tPh;
tNew = ((-1)*tOld*rad*rad)/((facto+1)*(facto+2));
tPh = tNew;
radPh = tNew;
facto = facto + 2;
tDiff = tOld - tNew;
cosAns = radPh;
}
return cosAns;
}
int main()
{
int precision = 10;
int choice;
//Title and Menu
cout << endl << "==============" << endl << " TRIGONOMETRY " << endl << "==============";
cout << endl << endl << "Current Precision: " << precision;
cout << endl << "Select:";
cout << endl << "1. Change Decimal Precision";
cout << endl << "2. Calculate Cos and Sin";
cout << endl << "9. Exit";
while (true)
{
//User Prompt
cout << endl << endl << "Please enter your choice. => ";
cin >> choice;
if (choice == 1)
{
cout << endl << "Please enter a value between 2 and 10. => ";
cin >> precision;
cout << "Current precision is " << precision;
}
if (choice == 2)
{
float angle, anglePh;
float pi = 3.14159265358979323846264338327950288419716;
char angleType;
cout << endl << "Please enter an angle. => ";
cin >> angle;
cout << endl << "Is the angle in degrees or in radian?";
cout << endl << "Input D if it's in degrees,";
cout << endl << "Input R if it's in radian. => ";
cin >> angleType;
if (angleType == 'D')
{
anglePh = angle;
angle = angle*pi/180;
cout << anglePh << " degrees = " << angle << " radian";
}
cout << endl << "Calculating Cos...";
cout <<cos(angle, precision);
cout << endl << "Calculating Sin...";
}
if (choice == 9)
{
break;
}
}
}

How do i fix this error: undefined reference to `distance(float, float, float, float)'

So I am not really sure what to do here, I have gone back over my code multiple times and it all seems to be right but I keep getting the error code
Stubblefield9.cpp:74: undefined reference to `distance(float, float, float, float)'
collect2.exe: error: ld returned 1 exit status
Here is my code if anyone can help me.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
const float pi=3.14;
int choice;
char again;
do
{
cout << " IHCC Computer Science Registration Menu\n";
cout << " ======================================\n";
cout << " 1. The Volume of a Cone\n";
cout << " 2. The Volume of a Sphere\n";
cout << " 3. The Area of an Octagon\n";
cout << " 4. The Destance between two Points\n";
cout << " ======================================\n";
cout << " Enter your selection: ";
cin >> choice;
switch (choice)
{
case 1:
float coneRadius,coneHeight,coneVolume;
cout<<"Enter the Radius of the cone:";
cin>>coneRadius;
cout<<"\nEnther the Height of the Cone: ";
cin>>coneHeight;
coneVolume=pi*coneRadius*coneRadius*coneHeight/3;
cout<<"\nThe Volume of a Cone with Radius ("<< coneRadius << ") and Height (" << coneHeight << setprecision(2) << fixed << ") is " << coneVolume;
break;
case 2:
float sphereRadius,sphereVolume;
cout << "Please insert the Radius: ";
cin >>sphereRadius;
sphereVolume = (4/3)*(pi)*(sphereRadius*sphereRadius*sphereRadius);
cout<<"Volume with radius "<< setprecision(1) << fixed << sphereRadius << setprecision(2) << fixed << " is "<<sphereVolume;
break;
case 3:
float octagonSide, octagonArea;
cout << "Input side length: ";
cin >> octagonSide;
octagonArea =(2 * (1 + sqrt(2)) * octagonSide * octagonSide);
cout << "\nThe area of the octagon with side length (" << octagonSide << setprecision(2) << fixed << ") is "<< octagonArea;
break;
case 4:
float x, y, a, b, answer;
float distance(float x, float y, float a, float b);
cout << "Enter the points for the coordinates";
cout << endl;
cout << "Point x for first coordinates: ";
cin >> x;
cout << endl;
cout << endl;
cout << "Point y for first coordinate: ";
cin >> y;
cout << endl;
cout << endl;
cout << "Point x for the second coordinate: ";
cin >> a;
cout << endl;
cout << endl;
cout << "Point y for the second coordinate: ";
cin >> b;
cout << endl;
cout << endl;
answer = distance(x, y, a, b);
cout << "The answer is " << answer;
break;
default:
cout << "Not a Valid Choice. \n";
cout << "Choose again.\n";
cin >> choice;
break ;
}
cout << "\n\n Would you like to do it again(y or n)";
cin >> again;
} while( again == 'y' || again == 'Y' );
return 0;
}
You get that error because you try to call a function distance() that is declared in your code by
float distance(float x, float y, float a, float b);
but not defined.

inf output computing line slopes

I am very new at C++.
I wrote this code below which is supposed to tell me if 2 lines have an intersection point, so I figured two lines with equal "M" in the y=Mx+B equation should not intersect and all others would.
The program seems to be understanding this, but unless the slope of the inputted line segment is 0 it outputs inf or -inf.
why is this happening?
#include <iostream>
using namespace std;
int main ()
{
typedef double vector2d[2];
vector2d pointA, pointB, pointC, pointD;
double LineSeg1, LineSeg2;
double yes, no;
cout << "Enter x for point A: ";
cin >> pointA[0];
cout << "Enter y for point A: ";
cin >> pointA[1];
cout << "Point A = (" << pointA[0] << "," << pointA[1] << ")" << endl;
cout << "Enter x for point B: ";
cin >> pointB[0];
cout << "Enter y for point B: ";
cin >> pointB[1];
cout << "Point B = (" << pointB[0] << "," << pointB[1] << ")" << endl;
cout << "Enter x for point C: ";
cin >> pointC[0];
cout << "Enter y for point C: ";
cin >> pointC[1];
cout << "Point C = (" << pointC[0] << "," << pointC[1] << ")" << endl;
cout << "Enter x for point D: ";
cin >> pointD[0];
cout << "Enter y for point D: ";
cin >> pointD[1];
cout << "Point D = (" << pointD[0] << "," << pointD[1] << ")" << endl;
LineSeg1 = ((pointB[1]-pointA[1])/(pointB[0]-pointB[0]));
cout << "slope segment 1 = (" << LineSeg1 << endl;
LineSeg2 = ((pointD[1]-pointC[1])/(pointD[0]-pointC[0]));
cout << "slope segment 2 = (" << LineSeg2 << endl;
if ( LineSeg1 == LineSeg2 ) {
cout << "no\n";
}
else ( LineSeg1 != LineSeg2 ) ;{
cout << "yes\n";
}
return 0;
}
This line:
LineSeg1 = ((pointB[1]-pointA[1])/(pointB[0]-pointB[0]));
has a divide by zero error.
I believe the equation should be:
LineSeg1 = ((pointB[1]-pointA[1])/(pointB[0]-pointA[0]));