Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

c# Array & loops


  • Please log in to reply
1 reply to this topic

#1 wundermutt

wundermutt

  • Members
  • 3 posts
  • OFFLINE
  •  
  • Local time:11:38 PM

Posted 17 July 2010 - 08:50 PM

Home Work ? (Sales Commissions) Use a one-dimensional array to solve the following problem: A company pays its salespeople on a commission basis. The salespeople receive $200 commission basis 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 (200+9%x5000), or a total of $650. Write an application (using an 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
:thumbsup: $300–399
c) $400–499
d) $500–599
e) $600–699
f) $700–799
g) $800–899
h) $900–999
i) $1000 and over

My Code that does not work: I am missing a step, do I need an if statement?

public class Array
{
static void Main(string[] args)
{
int[] frequency = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };// declare array

double sales = 0; //declare variable

double salary; //declare variable

Console.WriteLine("Please enter your total sales, enter -1 when you are done."); //prompt user for input

int input = Convert.ToInt32(Console.ReadLine()); //read input from user

salary = (input * 0.09) + 200;

for (int counter = 0; counter < frequency.Length; counter++)
Console.WriteLine("{sales,10}{1,9}", counter, frequency[counter]);

BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:09:38 PM

Posted 21 July 2010 - 02:16 PM

Let's take this step by step shall we? First, are you able to correctly calculate the sales amount for each person entered?

Once you are able to do that, use an if statement to figure out which counter in the array should be incremented. If the income is between $200–299, increment the first index in the array (which is array[0]), and so on for each income entered.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users