Question: How do i fix my code to match my rubric for my HW . How do I fix the alignment for when I enter 0

How do i fix my code to match my rubric for my HW. How do I fix the alignment for when I enter 02 and the when I enter 2.11 I get -nan(ind) instead of invalid Input
Also make sure it matches my rubric : "Beside main, write a single function exactly like the following:
bool isoscelesTriangleHeightAndArea (XXXX base, XXXX hypotenuse, XXXX height, XXXX area);
where XXXX is the correct type that you decide.
It calculates both the height and area of an isosceles triangle given its base length and hypotenuse length.
There must be no other defined function in the program beside isoscelesTriangleHeightAndArea() and main()
The function isoscelesTriangleHeightAndArea (base, hypotenuse, height, area) has EXACTLY FOUR PARAMETERS.
-Input parameters to the functions are the base and hypotenuse of the triangle. Function cannot modify the input parameters.
-Output parameters of the function are the area and height of the triangle. Function must calculate and modify these 2 parameters.
-Function must have a boolean return (success or failure) to indicate whether the calculation is successful or not.
-This function returns true if both base and hypotenuse are not negative (0 base is valid).
-There is also a validation rule that the following expression cannot be negative to avoid calculation of square root of a negative number.
If validation fails then the function returns false and skips calculations for the height and area.
-The function isoscelesTriangleHeightAndArea() should Not use any "cin" or "cout". Only the main() function will contain "cin" and "cout".
-The main() function calls the function in a loop until the user enters 00. These are the "Sentinel" values that stop the loop (chapter 5). If only one input is 0 and the other input is positive, the loop will keep going.
-Use variable name base and hypotenus, not a and b.
The following is a basic simple code without loop to test your function:
#include
#include
// Function prototype
//-----------
int main()
{
double base =2.5, hypotenuse =3, height, area;
bool success = isoscelesTriangleHeightAndArea(base, hypotenuse, height, area);
if (success)
{
cout "Triangle height is " height endl;
cout "Triangle area is" area endl;
}
else
cout "Invalid Input!" endl;
// Expected output is:
// Triangle height is2.72718
// Triangle area is3.40897
}
Output is:
Triangle height is2.72718
Triangle area is 3.40897
and If your function code does not work with the above given main() code, your score will be very low because the function is incorrect.
The result of the function call is used in main() to decide what to display for the output: if the return value is true then it means the calculation result is stored in area and height, and if false it means that the input parameters base and hypotenuse are invalid.
After using the simple test code above, write code in main() to accept multiple base and hypotenuse inputs and display the results by writing a Sentinel loop (chapter 5) that runs until the user enters 0 and 0 for the 2 inputs.
Note:
Do not use an infinite loop as a sentinel loop.
Do not use "break" / "continue" statements.
A good sentinel loop does not use an extra "if" statement inside loop to check for the sentinel value 0 and 0.
If the sentinel loop is correct, the function is NOT called when input is 0 and 0 because these values will make the loop stop.
There is no need to control the number of decimal digits in the results
The output text and results should be aligned nicely as seen in the following samples.
Write the function prototype before main() and write the full function definition after main()."
#include
#include
using namespace std;
bool isoscelesTriangleHeightAndArea(double base, double hypotenus, double& height, double& area);
int main()
{
double base, hypotenuse, height, area;
cout "This program calculates the height and the area of an isoceles triangle.
";
do {
cout "Enter the base and side length of triangle seperated by spaces, or enter 00 to exit: ";
cin >> base >> hypotenuse;
bool success = isoscelesTriangleHeightAndArea(base, hypotenuse, height, area);
if (success)
{
cout "Triangle height is " height endl;
cout "Triangle area is " area endl;
}
else
if (base ==0 && hypotenuse ==0)
{
cout endl;
}
else
cout "Invalid Input!" endl;
} while (base !=0|| hypotenuse !=0);
return 0;
}
bool isoscelesTriangleHeightAndArea(double base, double hypotenus, double& height, double& area)
{
if (base >=0 && hypotenus >0)
{
height = sqrt(hypotenus * hypotenus -((base * base)/4));
area =(base * height)/2;
return true;
}
else
{
return false;
}
}
How do i fix my code to match my rubric for my HW

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!