Not sure if others have come acrossed this bit I have a program for a C# class I am taking and during my troubleshooting I have found that if I turn on a breakpoint and then press F5 to continue until the program finishes I am receiving different results than if I didn't insert a breakpoint. (Put breakpoint at 1st curly bracket after AddToSumCount(rollSum); line in RollDice() method):
Here is a copy of my code if you want to see it: -
using System;
-
using System.Collections.Generic;
-
using System.Text;
-
-
namespace Lab5_Ex2
-
{
-
class TwoDiceStats
-
{
-
//declare class variables
-
private int dice1Roll, dice2Roll, rollSum;
-
-
//declare & create class arrays
-
int[] sumArray = new int[13];
-
int[] dice1Array = new int[37];
-
int[] dice2Array = new int[37];
-
int[] calcSumArray = new int[37];
-
-
public TwoDiceStats()
-
{
-
}
-
-
public void RollDice()
-
{
-
-
for (int roll = 1; roll < dice1Array.Length; roll++)
-
{
-
//Roll dice# 1 using Random method
-
Random randomNumber = new Random();
-
dice1Roll = randomNumber.Next(1, 7);
-
dice1Array[roll] = dice1Roll;
-
//Roll dice# 2 using Random method
-
dice2Roll = randomNumber.Next(1, 7);
-
dice2Array[roll] = dice2Roll;
-
-
//Calculate sum of values rolled
-
rollSum = dice1Roll + dice2Roll;
-
calcSumArray[roll] = rollSum;
-
-
//Add to Sum count
-
AddToSumCount(rollSum);
-
}
-
-
}
-
-
//Add to sum count Method
-
public void AddToSumCount(int sum)
-
{
-
sumArray[sum]++;
-
}
-
-
//Display Results Method
-
public void DisplayResults()
-
{
-
Console.WriteLine("Roll #\tDice 1\tDice 2\tSum\t\t\tRoll #\tDice 1\tDice 2\tSum");
-
Console.WriteLine("------\t------\t------\t---\t\t\t------\t------\t------\t---");
-
for (int i = 1; i < dice1Array.Length; i = i + 2)
-
{
-
Console.Write("{0,6}\t{1,6}\t{2,6}\t{3,3}", i, dice1Array[i], dice2Array[i], calcSumArray[i]);
-
Console.Write("\t\t\t{0,6}\t{1,7}\t{2,7}\t{3,3}\n", i + 1, dice1Array[i + 1], dice2Array[i + 1], calcSumArray[i + 1]);
-
}
-
-
Console.WriteLine("\n{0} {1,10}","Sum","Frequency");
-
Console.WriteLine("{0} {1,10}", "---", "----------");
-
-
for (int sum = 2; sum < sumArray.Length; sum++)
-
Console.WriteLine("{0,3} {1,10}", sum, sumArray[sum]);
-
}
-
}
-
-
class TwoDiceStatsTest
-
{
-
static void Main(string[] args)
-
{
-
//create class object
-
TwoDiceStats myDice = new TwoDiceStats();
-
-
//Call Roll Dice Method
-
myDice.RollDice();
-
-
//Call Display Results Method
-
myDice.DisplayResults();
-
-
//keep console open until user presses Enter
-
Console.Read();
-
}
-
}
-
}
-
1 1555
Please check again , it might happen some part of the code is not executing because of the break point.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Faith |
last post by:
Hi all,
I have a serious problem that I am not sure whether its a bug in the
Microsoft Visual C++ or something that I am doing wrong. The problem
is (as noted in the Subject) is that my program...
|
by: Wal Turner |
last post by:
Consider the following simple class:
public class ClassA
{
public static string VAR = "hello";
}
public void MethodA()
{
while(true)
|
by: Ash |
last post by:
Hi all,
I have a C# web application which calls a number of stored procedures.
I wish to step into the stored procedures while debugging i.e "Mix-mode
debugging":
I have completed the following...
|
by: AC [MVP MCMS] |
last post by:
Wierd situation here. Running ASP.NET 1.1 on Win2003. I have to manually
attach the debugger to a process in order to debug. So I set a breakpoint
in an obvious place (like within the Page.Load...
|
by: Chris Botha |
last post by:
I am creating a worker thread from inside an aspx page and the thread does
the stuff it should do, no problem.
However, I have noticed running it in the debugger that it seems as if the
threads...
|
by: noleander |
last post by:
Hi. Ive been using Visual C++ for two years on an application. The
application is one solution, containing 10 projects. 9 of the projects build
libraries (*.lib). I've been debugging the...
|
by: =?Utf-8?B?TWljaGFlbA==?= |
last post by:
Hi Everyone,
I just started to get this error today.
"The breakpoint will not currently be hit. The source code is different then
the original.
It seems to walk right over my breakpoints. I'm not...
|
by: Stephany Young |
last post by:
When one uses the System.Diagnostics.Process.Start method to launch a common
or garden Console application, one can set the WindowStyle property of the
StartInfo object to ProcessWindowStyle.Hidden...
|
by: Joseph Geretz |
last post by:
I'm using the Request Filter documentation which can be found here:
http://msdn.microsoft.com/en-us/library/system.web.httprequest.filter.aspx
In this example, two filters are installed, one...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
| |