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. I need help with errors.

I need help with errors.

Scheduled Pinned Locked Moved C#
helpcsharptutorial
4 Posts 4 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.
  • A Offline
    A Offline
    Alex501
    wrote on last edited by
    #1

    I dont know how to fix my error. Could someone help me out. I use C# expression. namespace ConsoleApplication1 { private void rand_seed() { int seed = (int)(time(0)); RandomNumbers.Seed(seed); } private double get_RandomNum(double x, double y) { return x + (y - x) * RandomNumbers.NextNumber() * (1.0 / RAND_MAX); } private static int Main() { rand_seed(); double x_cor = 0; double y_cor = 0; double x_sum = 0; double y_sum = 0; double x_y_total = 0; int num_darts = 0; int num_hits = 0; int num_misses = 0; double pi_approx = 0; Console.Write(" Throw the dart: "); num_darts = SimulateCin.ReadToWhiteSpace(true); Console.Write("\n"); if (num_darts != 0) { for (int i = 0; i < num_darts; i++) // Start of for loop inside the while loop { x_cor =get_RandomNum(1.0, -1.0); y_cor =get_RandomNum(-1.0, 1.0); x_sum = (x_cor * x_cor); y_sum = (y_cor * y_cor); x_y_total = Math.Sqrt(x_sum + y_sum); if (x_y_total <= 1) { num_hits++; } else { num_misses++; } } } // end of if loop pi_approx = (1.0 * num_hits /num_misses); Console.Write(" The value is "); Console.Write(pi_approx); Console.Write("\n"); return 0; } }

    D S 2 Replies Last reply
    0
    • A Alex501

      I dont know how to fix my error. Could someone help me out. I use C# expression. namespace ConsoleApplication1 { private void rand_seed() { int seed = (int)(time(0)); RandomNumbers.Seed(seed); } private double get_RandomNum(double x, double y) { return x + (y - x) * RandomNumbers.NextNumber() * (1.0 / RAND_MAX); } private static int Main() { rand_seed(); double x_cor = 0; double y_cor = 0; double x_sum = 0; double y_sum = 0; double x_y_total = 0; int num_darts = 0; int num_hits = 0; int num_misses = 0; double pi_approx = 0; Console.Write(" Throw the dart: "); num_darts = SimulateCin.ReadToWhiteSpace(true); Console.Write("\n"); if (num_darts != 0) { for (int i = 0; i < num_darts; i++) // Start of for loop inside the while loop { x_cor =get_RandomNum(1.0, -1.0); y_cor =get_RandomNum(-1.0, 1.0); x_sum = (x_cor * x_cor); y_sum = (y_cor * y_cor); x_y_total = Math.Sqrt(x_sum + y_sum); if (x_y_total <= 1) { num_hits++; } else { num_misses++; } } } // end of if loop pi_approx = (1.0 * num_hits /num_misses); Console.Write(" The value is "); Console.Write(pi_approx); Console.Write("\n"); return 0; } }

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      What is the error message you're getting?

      Dave

      1 Reply Last reply
      0
      • A Alex501

        I dont know how to fix my error. Could someone help me out. I use C# expression. namespace ConsoleApplication1 { private void rand_seed() { int seed = (int)(time(0)); RandomNumbers.Seed(seed); } private double get_RandomNum(double x, double y) { return x + (y - x) * RandomNumbers.NextNumber() * (1.0 / RAND_MAX); } private static int Main() { rand_seed(); double x_cor = 0; double y_cor = 0; double x_sum = 0; double y_sum = 0; double x_y_total = 0; int num_darts = 0; int num_hits = 0; int num_misses = 0; double pi_approx = 0; Console.Write(" Throw the dart: "); num_darts = SimulateCin.ReadToWhiteSpace(true); Console.Write("\n"); if (num_darts != 0) { for (int i = 0; i < num_darts; i++) // Start of for loop inside the while loop { x_cor =get_RandomNum(1.0, -1.0); y_cor =get_RandomNum(-1.0, 1.0); x_sum = (x_cor * x_cor); y_sum = (y_cor * y_cor); x_y_total = Math.Sqrt(x_sum + y_sum); if (x_y_total <= 1) { num_hits++; } else { num_misses++; } } } // end of if loop pi_approx = (1.0 * num_hits /num_misses); Console.Write(" The value is "); Console.Write(pi_approx); Console.Write("\n"); return 0; } }

        S Offline
        S Offline
        Skippums
        wrote on last edited by
        #3

        I am pretty certain that your methods need to be in a class. Try the following:

        namespace ConsoleApplication1 {
        public class ConsoleApplication1 {
        // Copy all your code except the namespace from above
        }
        }

        You may additionally need to set your startup class in the project properties to be ConsoleApplication1.ConsoleApplication1. Hope this helps,

        Sounds like somebody's got a case of the Mondays -Jeff

        C 1 Reply Last reply
        0
        • S Skippums

          I am pretty certain that your methods need to be in a class. Try the following:

          namespace ConsoleApplication1 {
          public class ConsoleApplication1 {
          // Copy all your code except the namespace from above
          }
          }

          You may additionally need to set your startup class in the project properties to be ConsoleApplication1.ConsoleApplication1. Hope this helps,

          Sounds like somebody's got a case of the Mondays -Jeff

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          :doh: I read this post and that went right over my head.

          Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          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