[Dev-C++] arrays, how to use with rand()
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: PETER C. <pca...@cc...> - 2004-07-06 04:22:17
|
hi everyone, thanx for all of the help on the last program. im still pretty lost on what to do with it though. below i want to roll a die a number of times, user input, and output:
the face which was rolled, the occurence for each face and the percentage for that face.
i have a lot of questions:
1) how do i create an array to hold an infinite number of rolls? i.e. if the user wanted to roll the die 1 million or 1 billion times. so far i've made two arrays of 6.
2) how to output the occurences and based on that the percentage. do i use the array i created?
3) since i am using 1+r%6 to determine range, are the faces 1-6 in elements 1-6 or do they stay in 0-5?
cpp is not my forte. im considering dropping my class. any suggestions based on the types of questions i've asked?
thanx again..
Peter/Panos
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
int rolls;
cout << "how many times do you want to roll the die? "; //how many times to roll die
cin >> rolls; //user input
int faces[6] = {0}; //array for storage of faces of die.
//used later to calculate percentage
int face;
srand(time(0)); //user wants new random #'s generated each time
int face_per;
int die[6] = {1,2,3,4,5,6};
for(int i = 0; i < rolls; i++){
face = rand();
face = 1+ face%6;
cout << "the die has rolled: " << face << endl;
}
return 0;
}
______________ ______________ ______________ ______________
ccny.cuny.edu
|