Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(In C++) We have been asked to code a program that will calculate the square root of a number. This is done by using the

(In C++) We have been asked to code a program that will calculate the square root of a number. This is done by using the following formula:

x is value you want the sqrt of

n is the value the user thinks is the answer

x = (n ^ 2 + x) / 2n

The user will enter in each of these values.

The above formula must be calculated over and over until the result equals the actual value.

If all goes well your program needs to tell what the actual sqrt value is. Followed by each rounds calculation with all values and which round of the calculation it is for. (round all values to 15 decimal places)

The program must give the user the following responses depending on how many times the calculation needs to be done. (1 - 5)

You are really good or you picked a number really easy like 4 You are pretty good You are not too bad but not real good You are not that good You are not that good at all

When it takes 6 or more You really don't have a understanding of square roots

Specifications that have to be followed:

You must use a "for" loop to allow users to guess as many square roots as they want.

You must use a "while" loop to do the formula square roots.

The checking of which statement to output needs to be done using a "switch" statement.

Outline of code:

Beginning info and extra libraries

Ask user how many times they would like to run the program (how many guesses would they like to attempt)

Use for loop to:

Ask user to enter the number of the square root they would like to figure out (x)

Ask user to enter the value they believe the square root to be (n)

User will be able to enter whole numbers and decimal places

If an easy square root selection is made, the while loop should not run at all

Once x and n are entered, use while loop to (in for loop):

Calculate the square root and check to see if their answer is correct or not

Use formula given above

Use built in square root function

Format this to round and store all values to 15 decimal places

Allow program to run however many times it takes for the use to get the correct answer or until they have used all of their attempts (asked in the beginning)

If they guess the correct answer before their attempts are up, they will be able to enter another square root value they would like to guess

For example, if they choose to attempt the program 4 times are guess their first square root in 2 tries, they will be able to pick another square root value for their final 2 attempts

Use switch statement for output statement (in for loop):

Display answer they typed in is displayed as 1 decimal place

Display answer calculated by program rounded to 15 decimal places

Display outputs above

Example of final output:

Here is/ are the results from calculating the square root of 17.0.

The actual value is: 4.1231056256177 (put answer to 15 decimal places)

Your calculations for round 1: 4.1234

Your calculations for round 2: 4.12356 (continue for how ever many times they decide to run the program, no more than 6 times)

You took 4 calculations to get the correct result.

*Insert statement from switch statement here*

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions