Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem on my assignment

Status
Not open for further replies.

williamwaihocheung

Programmer
Oct 14, 2007
4
CA
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Payroll
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void btnDisplayPayrollReport_Click(object sender, EventArgs e)
{
//define a streamReader and the location of the txtfile
StreamReader fileReader = File.OpenText(@"..\Payroll.txt");

//fefine variables
const int EOF = -1;
decimal HourlyRate = 0.0m;

decimal HoursWorked = 0.0m;
decimal GrossPay = 0.0m;
decimal FinalTotal = 840.50m;
string name;

//Muilt zone format

string heading = "{0, -14}{1,14}{2,14}{3,12}";
string content1 = "{0, -13}{1,13:c2}{2,13:c2}{3,13:c2}";
string ending = "{0, -13}{1,13:c2}";

//Perform Calculations
lstResult.Items.Add("Payroll Report for Week ending 11/15/06");
lstResult.Items.Add("");
lstResult.Items.Add(String.Format(heading, "Employee", "Hourly Rate", "Hours Worked", "Gross Pay"));
lstResult.Items.Add("");

//Read the txtfile if is not null + perform calculations
while (fileReader.Peek() != EOF)

{
name = fileReader.ReadLine();

HourlyRate = decimal.Parse(fileReader.ReadLine());

HoursWorked = decimal.Parse(fileReader.ReadLine());

GrossPay = HourlyRate * HoursWorked;
//using if statement when Hours worked over 40 and perform calculations
if (HoursWorked > 40m)
{
GrossPay = ((HoursWorked-40) *(HourlyRate * 1.5m)) + (40 * HourlyRate);

}
//list the result in a listbox
lstResult.Items.Add(String.Format(content1, name, HourlyRate, HoursWorked, GrossPay));


}
lstResult.Items.Add("");
lstResult.Items.Add(String.Format(ending, "Final Total", FinalTotal));




}

private void lstResult_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void Form1_Load(object sender, EventArgs e)
{

}
}
}

***************************************************

iam kind of stuck on the final total. how do i add all my grossPay and display on the listbox?
 
Ummm... this forum is cannot be used to solve assignments. For these, books are the recommended information source [thumbsup2]

Try to figure it out, it cannot be that hard [pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top