"Write a program that has a function prototype before main and an implementation of the
function after main. The function to be implemented is a coin toss simulation using the random number
generator. The function should return 1 or true 50% of the time and 0 or false 50% of the time. Use
srand and the system time to make the program run differently each time. (srand(time(NULL)); ).
Keep track of the number of head and tails for 10, 100, 1000, 10,000, 100,000 and 1,000,000 trials.
Output the number of heads and tails and number of each as a percentage of the total. Notice that the
more trials the more accurate your simulation becomes."
This is the assignment im trying to do. Im getting some errors.
C4244 'argument': conversion from 'time_t' to unsigned int' possible lossof data
Line 16
LNK1120 1 unresilved externals Line 1
LNK2019 unresolved external symbol "int_cdecl flip (void)" Line 1
Any ideas
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#include <iostream>
#include <stdio.h>
#pragma warning(disable: 4996)
#include<string>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <iomanip>
using namespace std;
int flip(); /*Function prototype*/
int main()
{
srand(time(NULL));
int tossTen = 10; /* toss coin ten times */
int tossHundred = 100; /* toss coin one hundred times */
int tossThousand = 1000; /* toss coin one thousand times */
int tossTenThou = 10000; /* toss coin ten thousand times */
int tossHunThou = 100000; /* toss coin one hundred thousand times */
int tossMillion = 1000000; /* toss coin one million times */
int headsTen = 0;
int headsHun = 0;
int headsThou = 0;
int headsTenThou = 0;
int headsHunThou = 0;
int headsMillion = 0;
int tailsTen = 0;
int tailsHun = 0;
int tailsThou = 0;
int tailsTenThou = 0;
int tailsHunThou = 0;
int tailsMillion = 0;
for (int i = 1; i <= tossTen; i++) /* start ten toss */
{
if (flip() == 0) {
headsTen++;
}
else {
tailsTen++;
}
} /* break ten toss*/
for (int i = 1; i <= tossHundred; i++) /* start hundred toss */
{
if (flip() == 0) {
headsHun++;
}
else {
tailsHun++;
}
} /* break hundred toss*/
for (int i = 1; i <= tossThousand; i++) /* start ten toss */
{
if (flip() == 0) {
headsThou++;
}
else {
tailsThou++;
}
} /* break thousand toss*/
for (int i = 1; i <= tossTenThou; i++) /* start ten toss */
{
if (flip() == 0) {
headsTenThou++;
}
else {
tailsTenThou++;
}
} /* break ten thousand toss*/
for (int i = 1; i <= tossHunThou; i++) /* start ten toss */
{
if (flip() == 0) {
headsHunThou++;
}
else {
tailsHunThou++;
}
} /* break Hundred Thousand toss*/
for (int i = 1; i <= tossMillion; i++) /* start ten toss */
{
if (flip() == 0) {
headsMillion++;
}
else {
tailsMillion++;
}
} /* break million toss*/
cout << setw(10) << "Heads" << setw(10) << "Tails" << endl;
cout << setw(10) << headsTen << setw(10) << tailsTen << endl;
cout << setw(10) << headsHun << setw(10) << tailsHun << endl;
cout << setw(10) << headsThou << setw(10) << tailsThou << endl;
cout << setw(10) << headsTenThou << setw(10) << tailsTenThou << endl;
cout << setw(10) << headsHunThou << setw(10) << tailsHunThou << endl;
cout << setw(10) << headsMillion << setw(10) << tailsMillion << endl;
system("pause");
return 0;
}
|