Question: Can someone help me with this c++ program? I am trying to get this program to output a certain answer and it is not working....

Can someone help me with this c++ program? I am trying to get this program to output a certain answer and it is not working.... I would appreciate if you could re-write the program for this output. I am trying to output the 5.34914 and 5.01139 alongside the 12.5 and 7.25.

I am trying to achieve this output, *this is the ideal/goal output

Can someone help me with this c++ program? I am trying to

but instead, I am getting this one, *this is the wrong output

get this program to output a certain answer and it is not

This is the program

#include

#include

double genNewGuess(double n, double oldGuess);

int main() {

double n, oldGuess, newGuess;

// Prompt user for input

std::cout

std::cin >> n;

// Validate input

if (n

std::cout

return 0;

}

// Initialize guess to n/2

oldGuess = n / 2.0;

std::cout

// Iterate through algorithm until stopping criterion is met

do {

newGuess = genNewGuess(n, oldGuess);

std::cout

oldGuess = newGuess;

} while (abs(newGuess - oldGuess) / oldGuess > 0.01); // Stopping criterion

// Output results

std::cout

return 0;

}

// Function to generate new guess

double genNewGuess(double n, double oldGuess) {

return (oldGuess + n / oldGuess) / 2.0;

}

Enter the Number to find square root: 25 Guessing... 12.5 7.25 5.34914 5.01139 The Final Guess: 5.00001 Actual Value: 5 Enter the Number to find square root: 2.3 Please enter a valid input(Positive Integer). Enter the Number to find square root: 25 Guessing... 12.5 7.25 Square root of 25:5

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 Databases Questions!