Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Unhandled Exception - and don't know why.

Unhandled Exception - and don't know why.

Scheduled Pinned Locked Moved C#
helpquestioncsharpdatabasedata-structures
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JMOdom
    wrote on last edited by
    #1

    :confused: I am getting a strange problem when I try to run a program for my C# class. I need to input 10 numbers each into two arrays. Then I need to extract each of the numbers and their corresponding numbers in the second array. These two get added together and stored into the third array. I can get my numbers into the two arrays. When I press Enter, I end up getting a message that there was an exception and it wants to e-mail it to Microsoft. Below is my code for displaying the results. At one time I could at least, get it to do a Console Write Line. Can anyone see where I’m making my mistake? I am only looking to find out why it is giving me the error message, and trying to send it to Microsoft. Any help would be appreciated. public static void DisplayNumbers(double anArray1, double anArray2, double anArray3) { string results = " "; int counter = 0; for (int x = 0; x < anArray3; x++) { anArray3 = anArray1 + anArray2; Console.WriteLine(); Console.WriteLine("{0}\t" + "+" + "\t{1}\t" + "=" + "\t{2}", anArray1, anArray2, anArray3); while (counter < 10) { counter++; results += "{0}\t" + " + " + "\t{1}\t" + " = " + "\t{2}" + anArray1 + anArray2 + anArray3; } string caption = "Array Methods Illustrated"; string outputMsg = "Array Numbers Shown\n\n" + "First\t" + "Second\t" + " " + " Sum\n"; MessageBox.Show(outputMsg, caption); } I'm listing the error I'm recieving and I'm also showing what is on Line 18. :doh: "Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array at Exer4Chpt7.Program.main<> in G:\Programs\Exer4Chpt7\ Exer4Chpt7\program.cs: Line 18" Line 18: double[] anArray1 = new double[10]; Thanks again. :)

    B 1 Reply Last reply
    0
    • J JMOdom

      :confused: I am getting a strange problem when I try to run a program for my C# class. I need to input 10 numbers each into two arrays. Then I need to extract each of the numbers and their corresponding numbers in the second array. These two get added together and stored into the third array. I can get my numbers into the two arrays. When I press Enter, I end up getting a message that there was an exception and it wants to e-mail it to Microsoft. Below is my code for displaying the results. At one time I could at least, get it to do a Console Write Line. Can anyone see where I’m making my mistake? I am only looking to find out why it is giving me the error message, and trying to send it to Microsoft. Any help would be appreciated. public static void DisplayNumbers(double anArray1, double anArray2, double anArray3) { string results = " "; int counter = 0; for (int x = 0; x < anArray3; x++) { anArray3 = anArray1 + anArray2; Console.WriteLine(); Console.WriteLine("{0}\t" + "+" + "\t{1}\t" + "=" + "\t{2}", anArray1, anArray2, anArray3); while (counter < 10) { counter++; results += "{0}\t" + " + " + "\t{1}\t" + " = " + "\t{2}" + anArray1 + anArray2 + anArray3; } string caption = "Array Methods Illustrated"; string outputMsg = "Array Numbers Shown\n\n" + "First\t" + "Second\t" + " " + " Sum\n"; MessageBox.Show(outputMsg, caption); } I'm listing the error I'm recieving and I'm also showing what is on Line 18. :doh: "Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array at Exer4Chpt7.Program.main<> in G:\Programs\Exer4Chpt7\ Exer4Chpt7\program.cs: Line 18" Line 18: double[] anArray1 = new double[10]; Thanks again. :)

      B Offline
      B Offline
      btsrinath
      wrote on last edited by
      #2

      Hi Y don't you change this line of code for (int x = 0; x < anArray3; x++) to for (int x = 0; x < 10; x++) and see. Sri

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups