Programming C++ Language, PLEASE HELP, Will upvote
Write a program that first generates two random decimal numbers within the range -100 to 100 inclusive. Next, generate a random number between 1 and 4 inclusive to correspond to each of our math operators (+, -, *, /). Finally, write out to a file called mathWorksheet.txt the following format:
A o B = ?
With A and B replaced by the two random numbers that were generated and o replaced by the random math operator. A complete example is shown below:
-15.15 * 82.311 = ?
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.
If you are satisfied with the solution, please rate the answer.
Thank You !
===========================================================================
# include <iostream>
# include <ctime>
# include <cstdlib>
# include <fstream>
using namespace std;
int main(){
srand(time(NULL)) ;
double first_decimal =
(double)rand()/(RAND_MAX+1)*(200)-100; // generate decimal betwen
=-100 to 100
double second_decimal =
(double)rand()/(RAND_MAX+1)*(200)-100; // generate decimal betwen
=-100 to 100
int oper = rand()%4 + 1; // generate a number either 1
2 3 or 4
char filename[] ="mathWorksheet.txt"; // file name and
path
ofstream outfile (filename) ; // open a file
switch(oper) {
case 1:
outfile<<first_decimal<<" +
"<<second_decimal<<" = "
<<first_decimal+second_decimal; break;
case 2:
outfile<<first_decimal<<" -
"<<second_decimal<<" = "
<<first_decimal-second_decimal; break;
case 3:
outfile<<first_decimal<<" *
"<<second_decimal<<" = "
<<first_decimal*second_decimal; break;
case 4:
outfile<<first_decimal<<" /
"<<second_decimal<<" = "
<<first_decimal/second_decimal; break;
}
outfile.close(); // close the file
}
===========================================================
Programming C++ Language, PLEASE HELP, Will upvote Write a program that first generates two random decimal...
Java Programming - Write a program that generates two random integers, both in the range 25 to 75, inclusive. Use the Math class. Print both integers and then display the positive difference between the two integers, but use a selection. Do not use the absolute value method of the Math class.
C++ programming please Write a program that will display random numbers in order from low to high. 1. Declare an integer array of size 100. Ask the user how many numbers to work with (n). It can be less than 100. 2. Generate random numbers from 10 to 50. 3. Write the random numbers to an output file named random.dat. Close the file. 4. Open random.dat for input and read the data values into your array. Pass your array to...
C++ language Write a program that 1. generates a random integer between 100 and 1000, call the number N 2. reads a file name from the keyboard 3. opens a file for output using the file name from step 2 4. generates N random numbers between 1 and 100 and writes them to the file from step 3 5. closes the file 6. opens the file from steps 3, and 4 for input 7. reads the numbers from the file...
PYTHON PROGRAMMING: DO NOT USE INPUT FUNCTION, use sys.argv Write a program that generates two random integer numbers between 1 and 100. Then, print out the numbers between the two randomly generated ones using a while loop. The output is shown below. Output: a) start:4, end:14 4 5 6 7 8 9 10 11 12 13 14 b) start:15, end:20 15 16 17 18 19 20
Write a program in C to generate random numbers. The program recieves 4 items on activation through argv: 1. Name of the data file 2. Number of items for program to generate 3. Range of numbers 4. Seed of the random number generator Example run: ./rand datafile.txt 20 1000 3127 Program must convert all numbers to ints using atoi(), must save all parameters into variables, opens the data file to write the random numbers into it, program loops to generate...
C language
Write a program that generates 20 random integers (ranging in between 0 to 100) and outputs all the even random numbers.
programming language
Write a program that will generate 5 random numbers between 20 and 80 and assign each to a variable of datatype double. You should use a random number generator seeded with time Using a series of if statements, determine which of the 5 variables contains the smallest value generated Print all five random numbers to the screen and print out the value that you determined was the smallest. All values should be printed with zero decimal places. 2.
Please use python 3 programming language Write a function that gets a string representing a file name and a list. The function writes the content of the list to the file. Each item in the list is written on one line. Name the function WriteList. If all goes well the function returns true, otherwise it returns false. Write another function, RandomRange that takes an integer then it returns a list of length n, where n is an integer passed as...
Write a program in Visual C# that generates 1000 random numbers with a user provided seed and upper limit on the random numbers generated. The numbers should be stored in a text file, each appearing on a newline, using the Windows Save File dialog. Each number should be separated by a newline.
question 2 in C programming please
PE-05b-01 (Six-sider) write a counter-controlled program that prompts the user to enter the number of times n to roll a six-sided die. The program should print to the screen the iteration of the loop and result for each roll 1 ) How many times would you like to roll? 3 roll 6 6 5 1 2) PE 05b 02 (Flash Cards) Write a counter-controlled program that creates addition problems for an elementary kid to...