help with sales commission program

I have worked on this program for the last 10 hours and I believe I am

Page 1 of 1

8 Replies - 2794 Views - Last Post: 14 January 2009 - 06:49 PM Rate Topic: -----

#1 cluelessinmn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-January 09

help with sales commission program

Post icon  Posted 13 January 2009 - 06:51 PM

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AssignFive810
{
	public class ComPay
	{

		private string empName;
		public double salary;

		public int grossSales;
		int[] range;
		int pay;

		double Salary
		{
			get
			{
				return salary;
			}
			set
			{
				salary = (grossSales * 0.09 + 200);
			}
		}
		public ComPay(string name, int[]rangeArray)
		{
			empName = name;
			range = rangeArray;
		}
   public void GetEmpName()
   {
	   while(empName != "quit")
	   {
		   Console.Write("Enter Employee Name or quit to display results: ");
		   empName = Convert.ToString(Console.ReadLine());
	   }
		Console.WriteLine("Employee Name:\n{0}", empName);
   }//end method GetEmpName
	
	   

	public void DisplayGrossSales()
	{
		while (grossSales != -1)
		{
			Console.Write("Enter Gross Sales or -1 to calculate: ");
			grossSales = Convert.ToInt32(Console.ReadLine());
		}//end while

		Console.WriteLine("GrossSales Amount:\n");
	}//end method DisplayGrossSales

	public void CalculateResults()
	{
		int[] count = new int[9];

		for (int counter = 0; counter < range.Length; counter++)
		{
			if (grossSales >= 1000)
				Console.WriteLine("1000");
			else
				if (grossSales >= 900)
					Console.WriteLine("900-999:");
				else
					if (grossSales >= 800)
						Console.WriteLine("800-899");
					else
						if (grossSales >= 700)
							Console.WriteLine("700-799");
						else
							if (grossSales >= 600)
								Console.WriteLine("600-699");
							else
								if (grossSales >= 500)
									Console.WriteLine("500-599");
								else
									if (grossSales >= 400)
										Console.WriteLine("400-499");
									else
										if (grossSales >= 300)
											Console.WriteLine("300-399");
										else
											if (grossSales >= 200)
												Console.WriteLine("200-299");
				for (int salary = 0; salary < range[counter]; salary++)
					Console.Write("{0}");

				Console.WriteLine();
			}//end outer for
		}//end method CalculateResults
		public void OutputResults()
		{
			Console.WriteLine("Wage Distribution:");

			for (int salary = 0; salary < range.Length; salary++)
				Console.WriteLine("{0} {1}",
					salary + 1, range[salary]);
		}//end method OutputResults
	}//end class ComPay
}//end namespace



Is This A Good Question/Topic? 0
  • +

Replies To: help with sales commission program

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5952
  • View blog
  • Posts: 23,215
  • Joined: 23-August 08

Re: help with sales commission program

Posted 13 January 2009 - 06:55 PM

Please fix your ending code tag. You can see that it did not work. It should be [ /code] (without the space).

Also, please ask your specific question in the body of the message. We've no idea what you're asking here.
Was This Post Helpful? 0
  • +
  • -

#3 cluelessinmn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-January 09

Re: help with sales commission program

Posted 13 January 2009 - 07:13 PM

I apologize for not posting correctly. My problem is the program I wrote is not compiling the gross sales * 0.09 + 200.00. after prompting employee name and gross sales input. I am not sure what I did wrong so any help I can get is much appreciated.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AssignFive810
{
	public class ComPay
	{

		private string empName;
		public double salary;

		public int grossSales;
		int[] range;
		int pay;

		double Salary
		{
			get
			{
				return salary;
			}
			set
			{
				salary = (grossSales * 0.09 + 200);
			}
		}
		public ComPay(string name, int[]rangeArray)
		{
			empName = name;
			range = rangeArray;
		}
   public void GetEmpName()
   {
	   while(empName != "quit")
	   {
		   Console.Write("Enter Employee Name or quit to display results: ");
		   empName = Convert.ToString(Console.ReadLine());
	   }
		Console.WriteLine("Employee Name:\n{0}", empName);
   }//end method GetEmpName
	
	   

	public void DisplayGrossSales()
	{
		while (grossSales != -1)
		{
			Console.Write("Enter Gross Sales or -1 to calculate: ");
			grossSales = Convert.ToInt32(Console.ReadLine());
		}//end while

		Console.WriteLine("GrossSales Amount:\n");
	}//end method DisplayGrossSales

	public void CalculateResults()
	{
		int[] count = new int[9];

		for (int counter = 0; counter < range.Length; counter++)
		{
			if (grossSales >= 1000)
				Console.WriteLine("1000");
			else
				if (grossSales >= 900)
					Console.WriteLine("900-999:");
				else
					if (grossSales >= 800)
						Console.WriteLine("800-899");
					else
						if (grossSales >= 700)
							Console.WriteLine("700-799");
						else
							if (grossSales >= 600)
								Console.WriteLine("600-699");
							else
								if (grossSales >= 500)
									Console.WriteLine("500-599");
								else
									if (grossSales >= 400)
										Console.WriteLine("400-499");
									else
										if (grossSales >= 300)
											Console.WriteLine("300-399");
										else
											if (grossSales >= 200)
												Console.WriteLine("200-299");
				for (int salary = 0; salary < range[counter]; salary++)
					Console.Write("{0}");

				Console.WriteLine();
			}//end outer for
		}//end method CalculateResults
		public void OutputResults()
		{
			Console.WriteLine("Wage Distribution:");

			for (int salary = 0; salary < range.Length; salary++)
				Console.WriteLine("{0} {1}",
					salary + 1, range[salary]);
		}//end method OutputResults
	}//end class ComPay
}//end namespace



View Postcluelessinmn, on 13 Jan, 2009 - 06:09 PM, said:

I apologize for not posting correctly. My problem is the program I wrote is not compiling the gross sales * 0.09 + 200.00. after prompting employee name and gross sales input. I am not sure what I did wrong so any help I can get is much appreciated.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AssignFive810
{
	public class ComPay
	{

		private string empName;
		public double salary;

		public int grossSales;
		int[] range;
		int pay;

		double Salary
		{
			get
			{
				return salary;
			}
			set
			{
				salary = (grossSales * 0.09 + 200);
			}
		}
		public ComPay(string name, int[]rangeArray)
		{
			empName = name;
			range = rangeArray;
		}
   public void GetEmpName()
   {
	   while(empName != "quit")
	   {
		   Console.Write("Enter Employee Name or quit to display results: ");
		   empName = Convert.ToString(Console.ReadLine());
	   }
		Console.WriteLine("Employee Name:\n{0}", empName);
   }//end method GetEmpName
	
	   

	public void DisplayGrossSales()
	{
		while (grossSales != -1)
		{
			Console.Write("Enter Gross Sales or -1 to calculate: ");
			grossSales = Convert.ToInt32(Console.ReadLine());
		}//end while

		Console.WriteLine("GrossSales Amount:\n");
	}//end method DisplayGrossSales

	public void CalculateResults()
	{
		int[] count = new int[9];

		for (int counter = 0; counter < range.Length; counter++)
		{
			if (grossSales >= 1000)
				Console.WriteLine("1000");
			else
				if (grossSales >= 900)
					Console.WriteLine("900-999:");
				else
					if (grossSales >= 800)
						Console.WriteLine("800-899");
					else
						if (grossSales >= 700)
							Console.WriteLine("700-799");
						else
							if (grossSales >= 600)
								Console.WriteLine("600-699");
							else
								if (grossSales >= 500)
									Console.WriteLine("500-599");
								else
									if (grossSales >= 400)
										Console.WriteLine("400-499");
									else
										if (grossSales >= 300)
											Console.WriteLine("300-399");
										else
											if (grossSales >= 200)
												Console.WriteLine("200-299");
				for (int salary = 0; salary < range[counter]; salary++)
					Console.Write("{0}");

				Console.WriteLine();
			}//end outer for
		}//end method CalculateResults
		public void OutputResults()
		{
			Console.WriteLine("Wage Distribution:");

			for (int salary = 0; salary < range.Length; salary++)
				Console.WriteLine("{0} {1}",
					salary + 1, range[salary]);
		}//end method OutputResults
	}//end class ComPay
}//end namespace


Here is my entry point code as well
sing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AssignFive810
{
	public class ComPayTest
	{
		public static void Main(string[] args)
		{
			int[] rangeArray = {0, 0, 0, 0, 0, 0, 
									  0, 0 , 0 };
			ComPay empPay = new ComPay("{0}", rangeArray);
			empPay.GetEmpName();
			empPay.DisplayGrossSales();
			empPay.CalculateResults();
		}
	}

}


Was This Post Helpful? 0
  • +
  • -

#4 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: help with sales commission program

Posted 13 January 2009 - 08:07 PM

I can see one problem....

You have this at the top...
public double salary;



then this at the bottom
for (int salary = 0; salary < range[counter]; salary++)
	  Console.Write("{0}");



You are declaring "salary" twice. You should be getting a compile error.
Was This Post Helpful? 0
  • +
  • -

#5 cluelessinmn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-January 09

Re: help with sales commission program

Posted 13 January 2009 - 08:45 PM

View Posteclipsed4utoo, on 13 Jan, 2009 - 07:07 PM, said:

I can see one problem....

You have this at the top...
public double salary;



then this at the bottom
for (int salary = 0; salary < range[counter]; salary++)
	  Console.Write("{0}");



You are declaring "salary" twice. You should be getting a compile error.

I am not getting a compile, says build succeeded. It is not computing gross Sales (entered by user input) or displaying the salary amounts from the Salary property. Fixed the error you pointed out, Thank you
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AssignFive810
{
	public class ComPay
	{

		private string empName;
		public double salary;
		public int grossSales;
		int[] range;

		double Salary
		{
			get
			{
				return salary;
			}//end get
			set
			{
				salary = (grossSales * 0.09 + 200.00);
			}//end set
		}//end property

		public ComPay(string name, int[]rangeArray)
		{
			empName = name;
			range = rangeArray;
		}
   public void GetEmpName()
   {
	   while(empName != "quit")
	   {
		   Console.Write("Enter Employee Name or quit to display results: ");
		   empName = Convert.ToString(Console.ReadLine());
	   }
		Console.WriteLine("Employee Name:\n{0}", empName);
   }//end method GetEmpName
	
	   

	public void GetGrossSales()
	{
		while (grossSales != -1)
		{
			Console.Write("Enter Gross Sales or -1 to calculate: ");
			grossSales = Convert.ToInt32(Console.ReadLine());
		}//end while

		Console.WriteLine("GrossSales Amount:\n");
	}//end method DisplayGrossSales

	public void CalculateSalary()
	{
		int[] range = new int[9];

		for (int counter = 0; counter < range.Length; counter++)
		{
			if (grossSales >= 1000)
				Console.WriteLine("1000");
			else
				if (grossSales >= 900)
					Console.WriteLine("900-999:");
				else
					if (grossSales >= 800)
						Console.WriteLine("800-899");
					else
						if (grossSales >= 700)
							Console.WriteLine("700-799");
						else
							if (grossSales >= 600)
								Console.WriteLine("600-699");
							else
								if (grossSales >= 500)
									Console.WriteLine("500-599");
								else
									if (grossSales >= 400)
										Console.WriteLine("400-499");
									else
										if (grossSales >= 300)
											Console.WriteLine("300-399");
										else
											if (grossSales >= 200)
												Console.WriteLine("200-299");

				for (int i = 0; i < range[counter]; i++)
					Console.Write("{0}");

				Console.WriteLine();
			}//end outer for
		}//end method CalculateResults
		public void OutputResults()
		{
			Console.WriteLine("Wage Distribution:");

			for (int pay = 0; pay < range.Length; pay++)
			   
				Console.WriteLine("{0} {1}",
					pay + 1, range[pay]);
		}//end method OutputResults
	}//end class ComPay
}//end namespace



I hope I am using this forum correctly
Was This Post Helpful? 0
  • +
  • -

#6 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: help with sales commission program

Posted 13 January 2009 - 08:51 PM

I see that a number of times you do something like this...

Console.Write("{0}");



that doesn't write anything because you aren't giving it the parameter.
Was This Post Helpful? 0
  • +
  • -

#7 cluelessinmn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-January 09

Re: help with sales commission program

Posted 13 January 2009 - 08:56 PM

View Posteclipsed4utoo, on 13 Jan, 2009 - 07:51 PM, said:

I see that a number of times you do something like this...

Console.Write("{0}");



that doesn't write anything because you aren't giving it the parameter.

I really am very new at this! I will go back to the text and read up on the proper way to pass the parameter. What I am getting is a bunch of 0s where the salary's should be displayed. Thank you sooo much for your help.
Was This Post Helpful? 0
  • +
  • -

#8 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: help with sales commission program

Posted 13 January 2009 - 09:08 PM

I don't see one place in your code where you are writing out the salary.
Was This Post Helpful? 0
  • +
  • -

#9 grains  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 14-January 09

Re: help with sales commission program

Posted 14 January 2009 - 06:49 PM

By declaring salary at the end of your CalculateSalary routine, you have created a local variable which makes it impossible for your routine to see the class variable salary that has your get and set methods.

Why are you looping through salary anyway? Don't you just need to print one salary, for the entered sales?

I would just declare a variable for salary, and then at the end of your CalculateSalary routine do something like

salary = grossSales*.09 + 200;


and then print it out. Or do you have a requirement to use a setter in this homework?

I find it helpful to write what I'm are trying to do in pseudo code or even plain English:

ask user for name and sales
print name, sales and salary where salary is grossSales * .09 + 200
[repeat as needed]

Don't add layers of complexity just because "you can"! The best programs are elegantly simple and simply elegant.

Good luck!


GRains
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1