...

View Full Version : Need C# Array help



DecenyDefied
10-04-2007, 06:25 PM
Hey

I need to make an array in C#, where I can put in 10 random numbers, and get them back but sorted from smallest to biggest.

What I have so far is:


using System;

namespace classtest1
{
class Program
{
static void selectionSort(int arr, int size)
{
int[] A = new int[10];
int i = 0;
int pass;
Console.WriteLine("Enter ten intergers and press enter after each:");
for (pass = 0; pass < size - 1; pass++)
A[i] = Int32.Parse(Console.ReadLine());

Console.WriteLine("Here are the sorted intergers");
for (pass = 0; pass < size - 1; pass++)

Console.WriteLine("{0}", A[i]);
Console.ReadLine();

}
static void Main()
{

return Array.sort;

}
}
}

If anyone can help out, I'd appreciate it!

Thanks.

nikkiH
10-04-2007, 06:30 PM
What do you need help with, specifically?
For homework help, you need to be very specific; the forum rules are strict about homework help.

DecenyDefied
10-04-2007, 06:37 PM
I just need to know what I am doing wrong.

The error I get says "error CS0117; 'System.Array' does not contain a definition for 'sort'

I think I might have a good idea going but I probably have errors in it so it wont sort properly. I just want to be able to inpu 10 random numbers, and get them back sorted from smallest to largest.

Dunna
10-05-2007, 05:03 AM
Let me get this straight: You write a function called selectionSort and instead of utilizing it or adding it as a function to the built in Array class, you just call the ambiguous Array.sort?
1. The error is occuring because returning Array.sort from the main function doesn't make any sense, because the function is void. A void function does not return a value. Judging by your error, Array may not even have a sort function anyhow.
2. Why is there an "arr" parameter in your selectionsort function if it's never utilized?
3. Why don't you ever call selectionSort?

nikkiH
10-05-2007, 02:32 PM
I just need to know what I am doing wrong.

The error I get says "error CS0117; 'System.Array' does not contain a definition for 'sort'

I think I might have a good idea going but I probably have errors in it so it wont sort properly. I just want to be able to inpu 10 random numbers, and get them back sorted from smallest to largest.

Well, there's a lot wrong, really.
You're calling the method totally wrong.

static void Main()
{

return Array.sort;

}

That makes no sense, and I'm surprised it even compiles, if it does. ;)
Your method name is selectionSort. You need to call Program.selectionSort() (you declared it static), but it appears to take arguments, so you'd need to pass those as well.

I'm not totally sure what the arguments are FOR, though. If you pass something called size, I'd imagine you meant to set an array size dynamically and use it in that loop like you do. But you hard-coded it to 10 and at the moment size is undefined because you aren't passing the value.

There's more wrong here than right, honestly. You may want to re-read your class material and ask for help from your instructor.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum