Click here to Skip to main content
15,908,901 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralMFC CString Question Pin
Stephen Doty11-Jul-05 17:32
Stephen Doty11-Jul-05 17:32 
GeneralRe: MFC CString Question Pin
Nish Nishant11-Jul-05 17:45
sitebuilderNish Nishant11-Jul-05 17:45 
GeneralRe: MFC CString Question Pin
Geert van Horrik11-Jul-05 23:52
Geert van Horrik11-Jul-05 23:52 
GeneralRe: MFC CString Question Pin
Stephen Doty12-Jul-05 6:50
Stephen Doty12-Jul-05 6:50 
GeneralRe: MFC CString Question Pin
Mister Transistor14-Jul-05 2:50
Mister Transistor14-Jul-05 2:50 
GeneralOptimizing Serial Read/Write Routines Pin
CNewbie11-Jul-05 16:33
CNewbie11-Jul-05 16:33 
GeneralRe: Optimizing Serial Read/Write Routines Pin
Bob Stanneveld11-Jul-05 20:36
Bob Stanneveld11-Jul-05 20:36 
GeneralWrite a program that simulates the rolling of two dice. Pin
bartman143711-Jul-05 16:10
bartman143711-Jul-05 16:10 
I am very new to the C++ programming scene and I am kind of lost on this one and need some help. I will post the code I have so far and maybe somebody can set me straight as to what I am doing wrong. The program should use a random number to simulate the first die and a second random number to simulate a second die. Then the program should calculate the sum of those two numbers. Each die can show an interger value from 1 to 6, so the sum of the two values will vary from 2 to 12, with 7 being the most frequent sum and 2 and 12 being the least frequent sums. The program should roll the dice 36,000 times. It should use a single-subscripted array to tally the numbers of times each possible sum appears. The results should be in tabular format. This one is really throwing me so if somebody could show me the right way to do this it would be a big relief.

#include "stdafx.h"

#using <mscorlib.dll>

using namespace System;

int _tmain()

{
Random *randomNumber = new Random();
int die1,
die2;
int frequency __gc[] = new int __gc[13];
double total;
//roll dice, calculate sum and display results
int RollDice(Random *randomNumber)
{
int die1, die2, workSum;

die1 = randomNumber->Next(1, 7);
die2 = randomNumber->Next(1, 7);
workSum = die1 + die2;
Console::WriteLine(S"Player rolled {0} + {1} = {2}",
die1.ToString(), die2.ToString(), workSum.ToString() );

return workSum;
} //end function RollDice


for (int roll = 1; roll <= 36000; roll++){
die1 = randomNumber->Next(2, 13);
++frequency[die1];
die2 = randomNumber->Next(2, 13);
++frequency[die2];

} //end of loop

total = 0;

for (int i = 1; i < 13; i++)
total += frequency[i];

Console::WriteLine(S"Face\tFrequency\tPercent");

//output frequency values
for (int x = 1; x < frequency->Length; x++)
Console::WriteLine(S"{0}\t{1}\t\t{2}%", x.ToString(),
frequency[x].ToString(),
(frequency[x]/total * 100).ToString("N") );


return 0;
} //end _tmain
GeneralRe: Write a program that simulates the rolling of two dice. Pin
Jose Lamas Rios11-Jul-05 16:29
Jose Lamas Rios11-Jul-05 16:29 
GeneralRe: Write a program that simulates the rolling of two dice. Pin
bartman143714-Jul-05 13:10
bartman143714-Jul-05 13:10 
GeneralRe: Write a program that simulates the rolling of two dice. Pin
Jose Lamas Rios14-Jul-05 17:08
Jose Lamas Rios14-Jul-05 17:08 
Generalone inportant thing Pin
LeeeNN11-Jul-05 14:40
LeeeNN11-Jul-05 14:40 
GeneralRe: one inportant thing Pin
Christian Graus11-Jul-05 16:58
protectorChristian Graus11-Jul-05 16:58 
GeneralRe: one inportant thing Pin
Weiye Chen11-Jul-05 17:28
Weiye Chen11-Jul-05 17:28 
GeneralRe: one inportant thing Pin
Christian Graus11-Jul-05 17:32
protectorChristian Graus11-Jul-05 17:32 
GeneralRe: one inportant thing Pin
Neelesh K J Jain11-Jul-05 20:10
Neelesh K J Jain11-Jul-05 20:10 
GeneralRe: one inportant thing Pin
Christian Graus12-Jul-05 13:10
protectorChristian Graus12-Jul-05 13:10 
GeneralRe: one inportant thing Pin
Bob Stanneveld11-Jul-05 20:38
Bob Stanneveld11-Jul-05 20:38 
GeneralRe: one inportant thing Pin
LeeeNN12-Jul-05 6:57
LeeeNN12-Jul-05 6:57 
GeneralCXX0017: Error: symbol &quot;buf_balance&quot; not found Pin
LeeeNN11-Jul-05 14:09
LeeeNN11-Jul-05 14:09 
GeneralRe: CXX0017: Error: symbol &quot;buf_balance&quot; not found Pin
Indivara11-Jul-05 14:28
professionalIndivara11-Jul-05 14:28 
GeneralRe: CXX0017: Error: symbol &quot;buf_balance&quot; not found Pin
Indivara11-Jul-05 18:19
professionalIndivara11-Jul-05 18:19 
GeneralRe: CXX0017: Error: symbol &quot;buf_balance&quot; not found Pin
Bob Stanneveld11-Jul-05 20:40
Bob Stanneveld11-Jul-05 20:40 
Generalpointer increment Pin
Indivara11-Jul-05 13:07
professionalIndivara11-Jul-05 13:07 
GeneralRe: pointer increment Pin
Jose Lamas Rios11-Jul-05 15:58
Jose Lamas Rios11-Jul-05 15:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.