I need help with errors.
-
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; } }
-
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; } }
-
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; } }
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
-
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
: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 )