473,396 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Issue with Breakpoint giving different results in application that is no breakpoint a

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:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace Lab5_Ex2
  6. {
  7.     class TwoDiceStats
  8.     {
  9.         //declare class variables
  10.         private int dice1Roll, dice2Roll, rollSum;
  11.  
  12.         //declare & create class arrays
  13.         int[] sumArray = new int[13]; 
  14.         int[] dice1Array = new int[37];
  15.         int[] dice2Array = new int[37];
  16.         int[] calcSumArray = new int[37];
  17.  
  18.         public TwoDiceStats()
  19.         {
  20.         }
  21.  
  22.         public void RollDice()
  23.         {
  24.  
  25.             for (int roll = 1; roll < dice1Array.Length; roll++)
  26.             {
  27.                 //Roll dice# 1 using Random method
  28.                 Random randomNumber = new Random();
  29.                 dice1Roll = randomNumber.Next(1, 7);
  30.                 dice1Array[roll] = dice1Roll;
  31.                 //Roll dice# 2 using Random method
  32.                 dice2Roll = randomNumber.Next(1, 7);
  33.                 dice2Array[roll] = dice2Roll;
  34.  
  35.                 //Calculate sum of values rolled
  36.                 rollSum = dice1Roll + dice2Roll;
  37.                 calcSumArray[roll] = rollSum;
  38.  
  39.                 //Add to Sum count
  40.                 AddToSumCount(rollSum);
  41.             } 
  42.  
  43.         }
  44.  
  45.         //Add to sum count Method
  46.         public void AddToSumCount(int sum)
  47.         {
  48.             sumArray[sum]++;
  49.         }
  50.  
  51.         //Display Results Method
  52.         public void DisplayResults()
  53.         {
  54.             Console.WriteLine("Roll #\tDice 1\tDice 2\tSum\t\t\tRoll #\tDice 1\tDice 2\tSum");
  55.             Console.WriteLine("------\t------\t------\t---\t\t\t------\t------\t------\t---");
  56.             for (int i = 1; i < dice1Array.Length; i = i + 2)
  57.             {
  58.                 Console.Write("{0,6}\t{1,6}\t{2,6}\t{3,3}", i, dice1Array[i], dice2Array[i], calcSumArray[i]);
  59.                 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]);
  60.             }
  61.  
  62.             Console.WriteLine("\n{0} {1,10}","Sum","Frequency");
  63.             Console.WriteLine("{0} {1,10}", "---", "----------");
  64.  
  65.             for (int sum = 2; sum < sumArray.Length; sum++)
  66.                 Console.WriteLine("{0,3} {1,10}", sum, sumArray[sum]);
  67.         }
  68.     }
  69.  
  70.     class TwoDiceStatsTest
  71.     {
  72.         static void Main(string[] args)
  73.         {
  74.             //create class object
  75.             TwoDiceStats myDice = new TwoDiceStats();
  76.  
  77.             //Call Roll Dice Method
  78.             myDice.RollDice();
  79.  
  80.             //Call Display Results Method
  81.             myDice.DisplayResults();
  82.  
  83.             //keep console open until user presses Enter
  84.             Console.Read();
  85.         }
  86.     }
  87. }
  88.  
Oct 19 '07 #1
1 1581
debasisdas
8,127 Expert 4TB
Please check again , it might happen some part of the code is not executing because of the break point.
Oct 19 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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...
4
by: Wal Turner | last post by:
Consider the following simple class: public class ClassA { public static string VAR = "hello"; } public void MethodA() { while(true)
2
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...
7
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...
5
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...
0
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...
7
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...
10
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...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.