Google Answers Logo
View Question
 
Q: Problam with Array in Visual Basic ( No Answer,   3 Comments )
Question  
Subject: Problam with Array in Visual Basic
Category: Reference, Education and News > Homework Help
Asked by: googlygas2005-ga
List Price: $20.00
Posted: 01 Mar 2005 18:52 PST
Expires: 31 Mar 2005 18:52 PST
Question ID: 483242
Hello, 

My name is Greg.

I am a student at Franklin University, in Columbus, Ohio. I am taking
Programming In Visual Basic.

I am programming in Visual Basic .NET, in a console application.  I am
doing the following assignment;

??.
A company pays its salespeople on a commission basis.  The salespeople
receive $200 per week, plus 9% of their gross sales for that week. 
For example, a salesperson who grosses $5000 in sales in a week
receives $200 plus 9% of $5000, or a total of $650.  Develop a console
program (using a one-dimensional array of counters) that determines
how many of the salespeople earned salaries in each of the following
ranges (assume that each salesperson?s salary is truncated to an
integer amount):

a)	$200-$299
b)	$300-$399
c)	$400-$499
d)	$500-$599
e)	$600-$699
f)	$700-$799
g)	$800-$899
h)	$900-$999
i)	$1000 an over

The program should first ask how many salespeople are in the company,
and then input as integers their grossed sales for that week.
....

I understand the formula for figuring out the salary; (grosssales *
.09) + 200 for the earned salary.

I also understand arrays to a point.  What I cannot figure out is how
to have the calculated salary fall into the array, which by my
understanding cannot have ranges in the elements (e.g. 200 - 299) and
add to the counter or frequency for the salary range.

I have considered creating Case statements for the ranges and using
those but, I am still unsure of how I would have the return variable
fall into the array.

Please help.

Thanks,
Greg
Answer  
There is no answer at this time.

Comments  
Subject: Re: Problam with Array in Visual Basic
From: willcodeforfood-ga on 01 Mar 2005 21:19 PST
 
Don't use the salary amount as the array index.  Make an array with 9
elements, with each one representing the salary categories.  Write a
function into which you can pass in the salary amount and have it
return an integer from 0 to 8, based on which range the salary fell. 
Use a case statement in the function that would return 0 if salary
$200-$299 and 1 if salary $300-$399, etc.

Say you call your 9-element array SalaryCounts, the function
GetGroupIndex and the salary amount is in a variable called
salaryAmount.  You can increment your array like this:

SalaryCounts( GetGroupIndex(salaryAmount) ) += 1

Just as a side note, what is supposed to happen if the salary is $299.50?

Also, what if the salary is $50.00?

It's always good to explicitly define these gray areas in your solutions.
Subject: Re: Problem with Array in Visual Basic
From: googlygas2005-ga on 01 Mar 2005 23:07 PST
 
Thank you very much. The case statements worked like a charm!

I have the following and as I step through I go through 9 iterations I
believe. Is the array setup correctly?

 Sub Main()

        Dim salespeople As Double
        Console.WriteLine("Please input number of salespeople:")
        salespeople = Console.ReadLine

        While salespeople <> 0


            Dim grosssales As Double
            Console.WriteLine("Please input gross sales for
salesperson: {0}", salespeople)
            grosssales = Console.ReadLine


            Dim salary As Double
            salary = (grosssales * 0.09) + 200
            Console.WriteLine("Salary is:{0} ", salary)


            getgroupindex(salary)

            Dim Salarycounts As Integer()
            Salarycounts = New Integer(9) {}


            For salaryamount = 0 To Salarycounts.GetUpperBound(0)

                Salarycounts(getgroupindex(salaryAmount)) += 1

            Next

            Console.WriteLine("Salary Amount is : {0}", salaryamount)


We have not covered exception handling yet, so I am unsure.  

I am assuming (bad thing to do, I know) that I will have to use a
windows message box, as in our example on pp 250 - 254 of Visual Basic
.NET, 2nd Ed., Dietel, 2002, Upper Saddle River, NJ, ISBN
0-13-029363-3. To properly display the results. Or figure the best way
in the console app to display that and allow for the tie into the # of
sales people.

Thanks again for all your help.

Greg

Kinda of tired and delerious (spelling?) right now
Subject: Re: Problam with Array in Visual Basic
From: willcodeforfood-ga on 02 Mar 2005 16:20 PST
 
You're on the right track.  This will help you along a bit:

Sub Main()

	' put all your declarations and initialization up here

	Dim salespeople As Double
	Dim grosssales As Double
	Dim salary As Double
	Dim Salarycounts As Integer()
	Salarycounts = New Integer(9) {0,0,0,0,0,0,0,0,0} ' be sure to
initialize arrays before using them

	Console.WriteLine("Please input number of salespeople:")
	salespeople = Console.ReadLine

        While salespeople <> 0
		Console.WriteLine("Please input gross sales for salesperson: {0}", salespeople)
		grosssales = Console.ReadLine

		salary = (grosssales * 0.09) + 200
		Console.WriteLine("Salary is:{0} ", salary)

                ' increment the appropriate salary-range counter
                Salarycounts(getgroupindex(salary)) += 1
		salespeople -= 1
	Wend


	' display program output	

	Console.WriteLine("Salary $200-$299 : {0}", Salarycounts(0) )
	Console.WriteLine("Salary $300-$399 : {1}", Salarycounts(0) )
	...

End Sub

Function getgroupindex(ByVal s as Integer)
	Select Case s
		Case 200 To 299
			Return 0
		... and so on, or however you've defined this function

End Function

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy