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 1581
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |