I am writing a code that accepts 4 values in a single line (the values are x,y coordinates of a vertex in a right angled triangle and x, y coordinates of another vertex in the same triangle) The code then calculates deltaX and deltaY, the length of the hypotenuse and the angle between the second point and the first point using atan2() function.
Then the code outputs/ displays the hypotenuse in the following way: length of hypotenuse(float)+single space+ angle between the points
The code is supposed run many times in the same console: the way it should run
but after i run the code once and press enter to run it once again it throws an error saying that abort() has been called, pls help! the way it is running and the error
The code is:
// Copyright A.T. Chamillard. All Rights Reserved.
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <cmath>
// IMPORTANT: Only add code in the section
// indicated below. The code I've provided
// makes your solution work with the
// automated grader on Coursera
// x and y coordinates for points
float Point1X;
float Point1Y;
float Point2X;
float Point2Y;
void GetInputValuesFromString(std::string Input);
/**
* Programming Assignment 2
* @return exit status
*/
int main()
{
// loop while there's more input
std::string Input;
std::getline(std::cin, Input);
while (Input[0] != 'q')
{
// extract point coordinates from string
GetInputValuesFromString(Input);
// Add your code between this comment
// and the comment below. You can of
// course add more space between the
// comments as needed
`
float deltaX{ Point2X - Point1X };
float deltaY{ Point2Y - Point1Y };
float hypo{ sqrtf(powf(deltaX, 2)+powf(deltaY, 2) )};
float a{ atan2((Point2Y-Point1Y),(Point2X-Point1X)) };
a = a * 180 / M_PI;
std::cout << hypo << " " << a;
`
// Don't add or modify any code below
// this comment
std::getline(std::cin, Input);
}
}
/**
* Extracts point coordinates from the given input string
* @param Input input string
*/
void GetInputValuesFromString(std::string Input)
{
// extract point 1 x
int SpaceIndex = Input.find(' ');
Point1X = std::stof(Input.substr(0, SpaceIndex));
// move along string and extract point 1 y
Input = Input.substr(SpaceIndex + 1);
SpaceIndex = Input.find(' ');
Point1Y = std::stof(Input.substr(0, SpaceIndex));
// move along string and extract point 2 x
Input = Input.substr(SpaceIndex + 1);
SpaceIndex = Input.find(' ');
Point2X = std::stof(Input.substr(0, SpaceIndex));
// point 2 y is the rest of the string
Input = Input.substr(SpaceIndex + 1);
Point2Y = std::stof(Input);
}
I tried googling it but i did not get what i was looking for