472,805 Members | 989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 1555
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: 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...
0
linyimin
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...
0
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...
2
isladogs
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...
14
DJRhino1175
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...
5
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...
0
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=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.