another question from my book, i would like to know if you think my answer is correct please
question: use a single subscripted array to solve the following problem: A company pays its salespeople on a commision basis. The salespeople receive £200/week, plus 9% of thier 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. Write a program (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"
b) "£300-£399"
c) "£400-£499"
d) "£500-£599"
e) "£600-£699"
f)"£700-£799"
g)"£800-£899"
h)"£900-£999"
i)"£1000 and over"
here is what i came up with
Code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Ex7_4
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.ComponentModel.Container components = null;
Random ranNum = new Random();
string[] salary = {"£200-£299", "£300-£399", "£400-£499", "£500-£599",
"£600-£699", "£700-£799", "£800-£899", "£900-£999",
"£1000 and over"};
int[] frequency = new int[ 10 ];
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(104, 24);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(104, 23);
this.button1.TabIndex = 0;
this.button1.Text = "Compute Salary";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(16, 88);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(288, 176);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(320, 273);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
textBox1.Text = "salary\t\t\tfrequency\r\n";
for(int i=1; i<frequency.Length; i++)
{
int wages = ranNum.Next(1, 10);//generate random number
frequency[wages]++;//update array of counters
}
for(int i=0; i<salary.Length; i++)//display output
{
textBox1.Text += salary[i] + "\t\t" + frequency[i + 1] + "\r\n";
}
}
}
}
im asking for help here because i think the part of the question that mentions 9% etc is a red herring, does my solution answer the question correctly?
thanks in advance
luigi