Please help
* Student ID : Your student ID #.20129121 , Due date : April 15, 2015, Create function that produces a random number..Create a main function with a loop and shows histograms
Section 1 Create a function “int roll()” that returns a value from 1 to 5.
Section 2 Main Function. Set the random number seed with 1 followed by last 4 digits of your student ID.
Section 3 Call "roll" function 200 times while keeping count of each number. (You are required to use an array)
Section 4 Show the results, and display a histogram.
Section 5 Call "roll" function 8 times, and add those numbers
Section 6 Repeat "Section 5" 1,000,000 times while keeping count of each number. (You are required to use an array)
Section 7 Show the results, and display a histogram. This time each "*" represents 2000./*
the entire thing. i can't get it to sort like that on the side. im in the C++ class online and the teacher is terrible. he wont answer emails and or have office hours. heres what i have thus far
/*
Student ID : Your student ID #.20129121
Last four digts 9121
*/
#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<fstream>
#include<string>
using namespace std;
//function prototype
int roll();
int main ()
{
unsigned int id=19121;
//create a random seed of last 4 digits of student id followed by 1
srand(id);
//array to hold five random numbers
int arrCount[6]={0};
//call roll function 200 times
//and count corresponding value in array
for(int index=0;index<200;index++)
arrCount[roll()]++;
//print histogram number of times each value occures in the arrCount
for(int index1=1;index1<=5;index1++)
{
for(int index2=0;index2<arrCount[index1];index2++)
cout<<"*";
cout<<"."<<endl;
}
//calling roll function 8 times and adding those values in totalSum
int totalSum=0;
for(int index1=0;index1<8;index1++)
totalSum=+roll();
cout<<"Total sum of adding roll for 8 times "<<totalSum<<endl;
//create an array of size 5
int arrCount2[6]={0};
//call roll function for 1000000 times
for(int index=0;index<1000000;index++)
//call roll function and increment the corresponding value in array
arrCount2[roll()]++;
//print histogram number of times each value occures in the arrCount2
for(int index1=1;index1<=5;index1++)
{
//Get quotient of each count value at index1 by divididing by 2000
int count=arrCount2[index1]/2000;
//print the starts fro
for(int index2=0;index2<count;index2++)
cout<<"*";
cout<<"."<<endl;
}
//pause the program output on console
system("PAUSE");
return 0;
}//bottom of main
//Returns a random number
int roll()
{
srand(time(NULL));
return rand()%5+1;
}
the output comes out funky. i can't paste it in here for some reason
Section 6 Repeat "Call roll function 8 times, and add those numbers" 1,000,000 times while keeping count of each number. (You are required to use an array)
Section 7 Show the results, and display a histogram. This time each "*" represents 2000./*
You also make an elementary mistake on line, whose number I don't know due to the lack of use of the code tags. The issue relates to the purpose of the "seeding" of the random number generator.
Please edit your post and make sure your code is [code]between code tags [/code] so that it has syntax highlighting and line numbers, as well as proper indentation. http://www.cplusplus.com/articles/jEywvCM9/
ok i completely changed it up and got the output the way i want it but i still have a small problem. the first set of numbers on the example output (1: - 5:) are supposed to count the number of 1s -5s for 200 rolls with a tally (*). however when i set i<6 so it returns values 1 to 5 the count only adds up to like 150 or so. if i set it to i<8 it will add up to 200. Line 28 is what im talking about. please help its due tonight.
#include<iostream>
#include<iomanip>
using namespace std;
int roll()
{
return (rand() % 7) + 1;
}
void main()
{
int ary[9] = { 0 };
int arx[43] = { 0 };
int id = 19121;
srand(id);
int i, j;
for (i = 1; i<=200; i++)
{
ary[roll()]++;
}
for (i = 1; i < 8; i++)
{
cout << setw(1) << i << ":" << setw(6) << ary[i] << ':';