Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I got feedback from my professor about formula 2 not working in this program. The solution I want to find for Option 2 is

Hi, I got feedback from my professor about formula 2 not working in this program. The solution I want to find for Option 2 is the distance between 2 points, what exactly am I doing wrong here that its will not calculate it correctly? The rest are correct, I am just not understanding the problem with formula 2. Here is my code:

#pragma warning(disable:4996) // To enable deprecated scanf()

#include

#include

#include

int main() {

// Declare Variables

int menuOption = 0;

// Prompts

printf("FORMULA SELECTION MENU ");

printf("1.) Distance Conversion ");

printf("2.) 2D distance formula ");

printf("3.) Surface area of a pyramid ");

printf("-------------------------- ");

printf("Which formula would you like to run\?: ");

scanf("%d", &menuOption);

// Run Appropriate Formula

if (menuOption == 1) {

double centimeters = 0.0;

double inches = 0.0;

printf("Enter distance in centimeters: ");

scanf("%lf", ¢imeters);

inches = centimeters / 2.54;

printf("%.3lf centimeters = %.3lf inches... ", centimeters, inches);

}

else if (menuOption == 2) {

float x1, x2, y1, y2;

printf("Enter point x1 : ");

scanf("%f", &x1);

printf("Enter point y1 : ");

scanf("%f", &y1);

printf("Enter point x2 : ");

scanf("%f", &x2);

printf("Enter point y2 : ");

scanf("%f", &y2);

float x = x2 - x1;

x2 = y2 - y1;

x1 = x2 * x2;

y1 = y2 * y2;

double answer = sqrt(x1 + y1);

printf("The distance between two points is %.3lf ", answer);

}

else if (menuOption == 3) {

float edge, height;

printf("Enter the length of an edge of the pyramid : ");

scanf("%f", &edge);

printf("Enter the height of the pyramid : ");

scanf("%f", &height);

double hypotenuse, oppSide = height, adjSide = edge*(0.5);

hypotenuse = sqrt(pow(oppSide, 2.0) + pow(adjSide, 2.0));

double areaTriangle = 0.5 * hypotenuse * edge;

float areaSquare = edge * edge;

double answer = areaSquare + (areaTriangle * 4);

printf("The surface area of the triangle is : %5.3f units squared. ", answer);

}

else {

printf("That was not a valid menu option... ");

}

_getch();

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

Students also viewed these Databases questions