I am new to C# programming and have been working on this project for a week. Here's the logic:
1. Output total number of salary ranges:
200 - 299, 300-399, 400-499, 500-599, 600-699, 700-799, 800-899,
1000+
2. Input gross sales.
3. If quit (-1) go to step 8
4. Calculate the salary =$200 + 9% * gross sales (entered by user)
5. Determine the salary range that the calculated salary falls into.
6. Increment a counter for the salary range that was determined.
7. Repeat steps 2 thru 6.
8. Display the number of salaries falling into the salary ranges as indicated.
9. End.
Any help would be greatly appreciated.
Code:
static void Main(string[] args)
{
int grossSales = 0;
while (grossSales != -1)
{
Console.Write("Enter in the sales for the salesperson (-1 to quit): ");
grossSales = Int32.Parse(Console.ReadLine());
//store grossSales in each salary range array
int[] frequency = new int[9];
//calculate the salary for each item stored in salary range array
for (int counter = 0; counter < frequency; counter++)
frequency[counter] = 200 + ((9/10)* grossSales);
int[] getSalary = new int[];// array of salary of the salespeople
//for each salary, increment the appropriate frequency
foreach (int salary in getSalary)
++frequency[salary / 10];
Console.WriteLine("{0,20}{1,30}", "Salary Range", "Number of Salespeople");
//for each salary, print number
for (int salary = 0; salary < frequency.Length; salary++)
{
if (salary == 10)
Console.Write("1000 and over: ");
else
Console.Write("{0:D2}{1:D2}: ", salary * 10, salary * 10 + 9);
}
}
}
}
}
Last edited by apricotsun; February 16th, 2007 at 03:50 PM.
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
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?
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
i'll have to charge you for any further customization
... 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.
Kenneth Jones, .Net Framework BCL/CLR Guru
Join the fight, refuse to respond to posts that contain code outside of [ code ] tags
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.
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.
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.
Kenneth Jones, .Net Framework BCL/CLR Guru
Join the fight, refuse to respond to posts that contain code outside of [ code ] tags
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
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!) 2008, 2009,2010 In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
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.
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
Example attached.
Kenneth Jones, .Net Framework BCL/CLR Guru
Join the fight, refuse to respond to posts that contain code outside of [ code ] tags
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.