Code
-----------------------
#include <stdio.h>
#include <stdlib.h>
int roll()
{
return rand()%5+1;
}
void printHistogram(int counts[21])
{
for (int i=0; i<21; i++)
{
printf("\n%d:",i+4);
for (int j =0 ; j<counts[i]; j++)
{
printf("X");
}
}
}
int main()
{
int i, n, r1, r2, r3, r4;
printf("How many rolls do you want? ");
scanf("%d",n);
int testCounts[21] = {0};
for(i=0; i<n; i++)
{
r1 = roll();
r2 = roll();
r3 = roll();
r4 = roll();
int total = r1+r2+r3+r4;
printf("%d ",total);
testCounts[total-4] += 1;
}
printHistogram(testCounts);
return 0;
}
Output
-----------------
How many rolls do you want? 50
4:
5:
6:
7:XX
8:XXXXX
9:X
10:XXXXX
11:XXXXXXXXXXX
12:XXXX
13:XXXXXX
14:XXXXXX
15:XXXX
16:XXX
17:X
18:X
19:
20:X
21:
22:
23:
24:
Thank you!!! 4.1 [2 pts. int rollO Define a function roll() that takes no arguments, and...
How to write python code that is a dice rolling function that generates random numbers. The dice rolling function takes two arguments: the first argument is the number of sides on the dice and the second argument is the number of dice. The function returns the sum of the random dice rolls. For example, if I call roll dice(6,2) it might return 7, which is the sum of randomly chosen numbers 4 and 3. It somewhere along the lines of:...
I just need the code in c++ by using array and random number generation Write a function called rollDice. This function emulates rolling two 6-sided dice Choose two random numbers between 1 and 6 They should be random enough (pseudo-radom), not the same random number every time the function is run Add the numbers together and return the sum Note: it is not sufficient to merely randomly choose a number between 2 and 12, can you see why? Write a...
C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...
What is wrong with the following function definition? void fill(const int a[], int size) { for (int i = 0; i < size; i++) { a[i] = 0; } return; } Answers: The function cannot change the array parameter. The array should be passed as a call-by-reference, not call-by-value. The for loop causes an out-of-bounds indexing error. Nothing, the code works fine as is.
In C++ Write a function that accepts two int arrays of the same size. The first array will contain numbers and the second array will be filled out inside the function. The function should find all numbers in the array that are greater or equal to the average and fill out the second array with these numbers. You need to design the function. I tried this code but the errors returned were: expression must have a constant value #include<iostream> using...
In C++ 9) (5 pts) Complete the following function that takes 3 arguments of a circle : - radius (input argument) - area (output argument, to be calculated) - circumference (output argument, to be calculated) All arguments are double type. If a radius is negative, the function returns false, otherwise it returns true. The function does only calculation, and does nothing else. Assume that all #include are already there // Fill in your Function prototype bool circleAreaAndCircumference ( _______,...
This is for C++ #include <random> #include <iostream> #include <ctime> using namespace std; /* In the game of craps, a shooter rolls 2 dice and adds the dots on the upper most faces of the dice. 7 or 11 on the first roll wins, 2, 3, or 12 on the first roll loses, andthing else is call the point and the player rolls again The following program fragment uses 1-way if statements simulate the 1st roll of the dice. Replace...
dont use switch
E) 120 pts.] Write another function int main ) in C++(and comment the main in Q1.D) that displays the following menu using a do while loop: please choose from the following Menu: I: Populate array with 5 elements 2: Print Array 3: Reverse Array 0: Exit Based, on the user choice, you should call the appropriate function. For example, if the user: - chooses 1, then in function main you should call function populateArray (A, 5); -...
// PLACE YOUR NAME HERE #include <iostream> using namespace std; float findAverage (int [], int); // finds average of all //grades int findHighest (int [], int); // finds highest of all //grades int findFirstFail( int[]); int main() { int grades[100]; // the array holding 100 grades. int numberOfGrades; // the number of grades read. int pos; // index to the array. float avgOfGrades; // contains the average of the grades. int highestGrade; // contains the highest grade. int inderOfFail; //...
Write a C++ function, smallestIndex, that takes as parameters an
int array and its size and returns the index of the first
occurrence of the smallest element in the array. To test your
function, write a main that prompts a user for a list of 15
integers and outputs the index and value of the first occurrence of
the smallest value.
The program should print out
Enter 15 integers:
The position of the first occurrence of the smallest element in...