Prompt the user for the number of darts to throw

Assignment Help Programming Languages
Reference no: EM131323862

Assignment

After informing the user what the program does, prompt the user for the number of darts to throw. Also, prompt for a number of simulations (why not have the program simulate this dart throwing more than once). Then, for each "dart" to be thrown, generate a random x and y coordinate within this region. Calling the function rand() will give you a random number 0...INT_MAX. If you divide the number by INT_MAX, you'll be able to generate a random number in the interval [0,1). Remember to seed the random generator. After these random coordinates are generate, (i.e., a dart is thrown), see if the dart falls within the unit quarter-circle. Since the radius of the unit circle is 1, to determine if the dart is inside simply calculate the distance from the origin to the coordinate. If the distance is less than one, the dart must be inside the quarter circle. Otherwise, it falls outside this region. If the dart is inside the quarter circle, keep track of this by incrementing a count variable, say dartsInside. Once all the darts are thrown, divide the dartsInside by the total number of darts thrown to approximate the area of the quarter circle.

This has now successfully made an approximation of pi/4, but was only a throw of n darts. Your program is going to simulate throwing n darts m times. Just reset the count variable and run the approximation again. Each simulation will generate a new approximation of pi/4. We'll take the average of all these approximations to give our final approximation of pi. Normally, the average of m numbers is the sum of the data divided by m. However, in order to avoid overflow, convince yourself of the equality

a1+a2+...+am / m = a1 / m + a2 / m + ... am/m

Thus, instead of accumulating the approximations of pi, your program will accumulate the approximation divided by m. Once all the simulations are finished, multiply your value by four and print the programs approximation of pi.

Finally, to see different approximations, allow the user to repeat this process of throwing n darts m simulated times an indefinite number of times-until the user enters in a value indicated to quit. For example, the sentinel value could be 0. This program will also guard against bad data. When the user enters in a number, the number could be invalid - i.e., less than 0, or it could be a character. In either event, your program should handle this without crashing, recover from this bad data and continue execution.

Reference no: EM131323862

Questions Cloud

Find the maximum normal and shear stresses in beam : A linearly increasing load sits on a brass rail of length L. Find the centroid (4) of the cross section below. Using successive integration, find the maximum bending moment (5) and deflection (8) in the rail and their respective locations along th..
Design a program that asks the user to enter a string : Sum of Digits in a String Design a program that asks the user to enter a string containing a series of single digit numbers with nothing seperating them.
Why did you decide on this profession-health counselor : Part of developing your clinical mental health counselor identity is exploring your motivations for entering this profession. Why did you decide on this profession? What experiences have you had in the past that make you think this profession woul..
Calculate that the correct answer : For example, if you calculate that the correct answer is 514 mm Hg, simply type "510" in the box without the quotation marks (") or units as part of your answer.
Prompt the user for the number of darts to throw : After informing the user what the program does, prompt the user for the number of darts to throw. Also, prompt for a number of simulations (why not have the program simulate this dart throwing more than once).
Write the paper on domestic violence : Write the given paper assignment.- The topic is: "Domestic Violence: The After-Effects."- Also provide the Thesis statement.
Calculate the molarity of solution : Dr. Pepper has 40.0g of sugar per 12 oz. of liquid. Calculate the molarity of this solution. Put that molarity into your regression line and calculate the density (all other things being equal) of this sugar solution. Show your work
Probelm regarding the buffer solution : What mass of NaH2PO4 must be added to 1.20 L of 0.20 M Na2HPO4to make a buffer solution whose pH=6.90? pKa2(H3PO4)=7.21.
Why does the temperature of a solution increase : Why does the temperature of a solution increase if the reaction is exothermic? For example, in the precipitation of silver iodide, delta H is -110.7 kj. Why is this reaction exothermic and why does it cause the solution temperature to increase?

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd