USE C++ Problem 3: Prompt the user to enter a whole number of points to be used in the approximation and robustly confirm that the number of points is positive (remember always ask user to re-enter before any calculations are performed). Then calculate and output the approximation for pi. Run your program at least twice with the entered number of points varying by at least a thousand. Examine your results and add a comment to the end of your source code file stating the effect of using more points on the approximation of pi. The maximum random number in C++ is stored into a predefined constant called RAND_MAX.
| C++ CODE |
|
#include<iostream> #include<ctime> #include<cstdlib> #define seed 35791246 using namespace std; double estimatePi(long numIter); double Xpoint; double Ypoint; double Zpoint = 0; int points = 0; int main() { long numIter; double estimatedPi; cout<<"Input the number of points: "; cin>>numIter; if(numIter < 0) { cout<< "Number of points must be a positive integer."<<endl; return -1; } srand(seed); // seeding random number generator // calling estimatePi function estimatedPi = estimatePi(numIter); cout<<"Estimated pi ~= "<< estimatedPi<<endl;
} double estimatePi(long numIter) { int i = 0; double estimatedPi; while(i < numIter ) { Xpoint = (double)rand()/RAND_MAX; Ypoint = (double)rand()/RAND_MAX;
Zpoint = (Xpoint * Xpoint) + (Ypoint * Ypoint) ; if (Zpoint <= 1) { points++; } i++; } estimatedPi = (double)points / numIter * 4 ; return estimatedPi; } |
OUTPUT

USE C++ Problem 3: Prompt the user to enter a whole number of points to be...
Write a program which asks the user to enter a number. While the number is outside the range of 50 to 65 (exclusive). print "This is not valid input." and ask the user to re-enter a number. Remember to include a comment at the start of the program. 7 A- B I - : F F 2
Ask uFor Ex. "Prompt user to enter a number" = user enters 10, your program should output 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.ser to input a number, and then using a loop control statement (While, For, Do-While), output to the console the numbers beginning from 1, up to and including the number input by the user.
C++ Program Write a do-while loop that continues to prompt a user to enter a number less than 100, until the entered number is actually less than 100. End each prompt with a newline. Ex: For the user input 123, 395, 25, the expected output is: Enter a number (<100): Enter a number (<100): Enter a number (<100): Your number < 100 is: 25 #include <iostream> using namespace std; int main() { int userInput; /* Your solution goes here */...
Write C++ program to prompt user to enter a 3-digits number, say 371, to a variable called num. Then store each digit of this inputted number to three different variables called digit1, digit2 and digit3. Hence, when number entered is 371, digit1 is 3, digit2 is 7 and digit3 is 1. Display the value of inputted number followed by digit1, digit2 and digit3. Hint: You have to use / and % operator in this question.
Declare the following three variables: char letter; int number; double decimalNumber; Prompt the user to enter a letter. Read the letter into the variable letter Assign to the variable number the value from the variable letter Assign to the variable decimalNumber the value from the variable number Print the values of the three variables using the following format: Character: K Number: 75 Decimal number: 75 Test the program with the input letter a and copy the results into a comment...
IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...
build a phone number from digits entered by your user. Your program will loop until 10 valid digits have been entered. It will then use those digits to display the phone number entered using the format: XXXXXXXXXX (or (XXX) XXX – XXXX for extra credit). The program will ask for a digit, it will check to see if the digit is actually between 0 and 9 inclusively. If so, the digit will be stored as the next number in the...
C Code Create a tool in which a user can enter a string (up to 25 characters) and choose how they wish to manipulate the string from a menu your program will display (see the run-through). The program will continue to ask for commands until the user enters the “quit” command. The commands are: • “Replace All” If a user types “replace all” using ANY sort of capitalization, your program will prompt the user to enter the character to change...
For C++ program Your program should first prompt the user for the number of students they wish to enter. For each student, the user will be prompted to enter the student’s name, how many tests the student has taken, and the grade for each test. Each test’s grade will be inputted as a number representing the grade for that test. Once each student’s information has been entered, the program will display the number of students. Additionally, each student will have...
This program will ask the user to enter a number of players, then ask the user for each player's name and score. Once all of the players have been entered, the program will display a bar chart with each of their scores scaled as a percentage of the maximum score entered. See below for details on exactly how this should work - an example transcript of how the program should work is shown below (remember that values entered by the...