Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How can I modify my code (below) to meet the requirements that follows: Change the return type of your squareRoot() function to void, so that

How can I modify my code (below) to meet the requirements that follows:

Change the return type of your squareRoot() function to void, so that it cant return anything. We want the same behaviour as earlier, but instead of using the return value, we will now let the result be set to the value -1 if we call the function with a negative number. The reason this works is that the square root can never be negative. Since squareRoot() no longer returns a value, and we want the program to behave exactly like before, you will also have to do modifications to main() so that it works just like before, but using the result instead of the return value from squareRoot() to determine the printout. Since the program is expected to work like before from the users perspective, no example run is needed.

My code:

#include #include int squareRoot(float number, float *root) { if (number >= 0) { *root = sqrt(number); return 1; } else { return 0; } } int main(void) { float squareRootResult; int returnValue; float guess; printf("Enter a number: "); scanf_s("%f", &guess); returnValue = squareRoot(guess, &squareRootResult); if (returnValue == 1)

{ printf("The square root of the entered number is: %f", squareRootResult); } else { printf("It is not possible to calculate the square root of a negative number"); } 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

Online Market Research Cost Effective Searching Of The Internet And Online Databases

Authors: John F. Lescher

1st Edition

0201489295, 978-0201489293

More Books

Students also viewed these Databases questions