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 and the when I enter I get nanind 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 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 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 These are the "Sentinel" values that stop the loop chapter If only one input is 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 hypotenuse height, area;
bool success isoscelesTriangleHeightAndAreabase 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 is
Triangle area is
Output is:
Triangle height is
Triangle area is
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 that runs until the user enters and for the 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 and
If the sentinel loop is correct, the function is NOT called when input is and 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 isoscelesTriangleHeightAndAreadouble 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 to exit: ;
cin base hypotenuse;
bool success isoscelesTriangleHeightAndAreabase hypotenuse, height, area;
if success
cout "Triangle height is height endl;
cout "Triangle area is area endl;
else
if base && hypotenuse
cout endl;
else
cout "Invalid Input!" endl;
while base hypotenuse ;
return ;
bool isoscelesTriangleHeightAndAreadouble base, double hypotenus, double& height, double& area
if base && hypotenus
height sqrthypotenus hypotenus base base;
area base height;
return true;
else
return false;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
