Re: Help with arrays in C#
And did you have a question?
There are numerous problems in your code, I think you need to spend some time reading.
Major issues:
* Your variables are going out of scope each iteration of your while loop
* You setup arrays, but assign no values
* Your final output is being repeated each iteration of the while loop
Re: Help with arrays in C#
Sorry. My question was what is wrong with my code. Thank you for responding. I'm trying to figure out your answers. What do you mean out of scope? How do I fix it?
Re: Help with arrays in C#
Quote:
Originally Posted by apricotsun
Sorry. My question was what is wrong with my code. Thank you for responding. I'm trying to figure out your answers. What do you mean out of scope? How do I fix it?
There really is too much wrong with your code to even bother trying to teach it all to you here.
Code:
static void Main(string[] args)
{
int[] sales = new int[9];
int[] frequency = new int[9];
for(int counter = 0; counter < 9; counter++)
{
Console.Write("Enter in the sales for the salesperson: ");
sales[counter] = Int32.Parse(Console.ReadLine());
}
for (int counter = 0; counter < 9; counter++)
{
frequency[(Convert.ToInt32((sales[counter] * .09)) - 1)] = (frequency[(Convert.ToInt32((sales[counter] * .09)) - 1)] + 1);
}
int ranges = 200;
for (int counter = 0; counter < 9; counter++)
{
Console.WriteLine(ranges.ToString() + "-" + Convert.ToString(ranges + 99) + ": " + frequency[counter].ToString());
ranges = ranges + 100;
}
Console.ReadLine();
}
That should give you close to what you want, i'll have to charge you for any further customization :)
Re: Help with arrays in C#
Quote:
Originally Posted by crackersixx
i'll have to charge you for any further customization :)
... :D I'm glad my paycheck doesn't come from that solution.
On a serious note,
If you're not sure what "scope" means I think you should start off with some books on programming in C# before you jump into creating that type of program.
Don't get me wrong one of the best ways to learn is by learning as you go, but you should have a small amount of background before you start playing with salary calculations. Unless this is just a sample solution.
You can look at this thread, I've made several book recommendations in it.
Re: Help with arrays in C#
Quote:
Originally Posted by apricotsun
I am new to C# programming and have been working on this project for a week.
Are you taking a college computer programming course? If so, what is your major? Just curious.
Re: Help with arrays in C#
Thank you guys. Any help is deeply appreciated. I'm using C# for dummies. I guess I need a dummier version cause that book does not make much sense. Thank you for the book suggestions. I will buy them - as I really do need help:).
Re: Help with arrays in C#
Quote:
Originally Posted by apricotsun
Thank you guys. Any help is deeply appreciated. I'm using C# for dummies. I guess I need a dummier version cause that book does not make much sense.
LOL! Keep on banging away. I predict that you will experience that "AHA!!" sensation in a week or two when it all starts making sense. Don't give up. Then the fun really begins.
Re: Help with arrays in C#
You said you were new to C# programming... I assume you ment this was your first programming language then?
Sometimes those dummy books are not very good. I think they are written by dummies more then half the time. But see the recommendations in that thread, I explained the difference between those types of books, and what type of books you should try to get instead.
Good Luck.
Re: Help with arrays in C#
Yes. I am new to programming. That is why I am still trying to grasp the concepts that everyone assumes is second nature. I still have a lot of questions but am too embarrassed to ask. So I will have to get those books :)
Re: Help with arrays in C#
Can anyone explain to me what the following code means?
item = item > 9 ? 9 : item - 1;
Re: Help with arrays in C#
Please use code tags!
Code:
item = item > 9 ? 9 : item - 1;
is the same as
Code:
if (item > 9)
item = 9;
else
item = item - 1;
Re: Help with arrays in C#
Sorry for forgetting the code tags. Thank you for explaining that to me. Really appreciate it.
Re: Help with arrays in C#
apricotsun,
If you have time, please go thro' the video courses available in the following websites. To me, video course are the best training materials to get me started pretty quick in any programming language.
Biginners Video Series on C## [Free] http://msdn.microsoft.com/vstudio/ex...g/default.aspx
Video Game development, Learn to write C# the fun way [Free]
http://www.microsoft.com/events/seri...nvideodev.mspx
[EDITED]
Finally, welcome to programming world and Good luck.
1 Attachment(s)
Re: Help with arrays in C#
Quote:
Originally Posted by poochi
If you are rich enough and have 100US$ to spend on programming materials, I would suggest you to become a life time member of
www.learnvisualstudio.net.
I sure hope they put that $100.00 to good use, like say, for example, fixing their home page.... its ridiculous :lol:
Example attached.