51 lines
1.3 KiB
C#
Executable File
51 lines
1.3 KiB
C#
Executable File
namespace lab5_7_CalebFontenot
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void calculateButton_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
// Variables
|
|
decimal sales;
|
|
decimal total = 0m;
|
|
|
|
// Declare a StreamReader variable.
|
|
StreamReader inputFile;
|
|
|
|
// Open the file and get a StreamReader object.
|
|
inputFile = File.OpenText("Sales.txt");
|
|
|
|
// Read the file's contents.
|
|
while (!inputFile.EndOfStream)
|
|
{
|
|
// Get a sales amount.
|
|
sales = decimal.Parse(inputFile.ReadLine());
|
|
|
|
// Add the sales amount to total.
|
|
total += sales;
|
|
}
|
|
|
|
// Close the file.
|
|
inputFile.Close();
|
|
|
|
// Display the total.
|
|
totalLabel.Text = total.ToString("C");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void exitButton_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
}
|
|
} |