- 0
Help with my C# project
-
Recently Browsing 0 members
- No registered users viewing this page.
-
Similar Content
-
Visual Studio Code 1.95 generates Python Docstring templates and more
By zikalify,
- microsoft
- visual studio code
- (and 3 more)
- 4 replies
- 1 view
-
- 0 replies
- 1 view
-
Visual Studio Code 1.94 launched with big startup speed improvements
By zikalify,
- visual studio code
- microsoft
- (and 6 more)
- 4 replies
- 0 views
-
- 3 replies
- 1 view
-
Microsoft introduces TypeScript 5.5: Explore the latest features and enhancements
By zikalify,
- microsoft
- typescript
- (and 4 more)
- 0 replies
- 0 views
-
Question
alyssajohnson
Hello everyone,
I'm currently enrolled in a college C# class. Now, for some reason I thought it'd be a good idea to take this course without having any prerequisites like intro to programming. To say nonetheless, I'm very afraid, lost, and confused. I've struggled through the semester, and tried to put a lot of effort into understanding the content. But, on this particular project of "Joe's Automotive" I'm lost on what's wrong with the code. I know exactly what the issue is,( every instance I have serviceTextBox.Text = total.ToString("c"); it's giving me an error) I'm just not entirely sure how to fix it. (For the record, I did ask for teacher assistance and she seemed lost herself on VS was mad about it.)
I'd really appreciate it if I could get some help on this, explaining what I could have done wrong already, and explaining how to fix it
Thank you for your time,
Alyssa
Here's the code:
//Alyssa Johnson
//Chapter 6 Project
//Joe's Automotive
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Chapter_6_PROJECT
{
public partial class chapter6 : Form
{
public chapter6()
{
InitializeComponent();
}
private void label7_Click(object sender, EventArgs e)
{
}
private void exitButton_Click(object sender, EventArgs e)
{
//closes out the program
this.Close();
}
//calculates all of the values
private void calculateButton_Click(object sender, EventArgs e)
{
//variables for later on in the code
OilLubeCharges();
Flushes();
Misc();
OtherCharges();
Tax();
TotalCharges();
}
//method for the oil and lube charges
//this is for the Oil & Lube group Box
private int OilLubeCharges()
{
int total = 0;
//if they checked oil add 26 for their total
if (oilCheckBox.Checked == true)
{
total += 26;
//serviceAndLaborLabel.Text = total.ToString("c");
serviceTextBox.Text = total.ToString("c");
//return total;
}
//In case lube was checked, to add 18 dollars
if (lubeCheckBox.Checked)
{
total += 18;
//adding 18 to the total becuase that's how much the lube job would cost
//serviceAndLaborLabel.Text = total.ToString("c");
return total;
}
else
{
return total;
}
}
//to calculate the flushes
//private void for all of the group boxes.
private int Flushes()
{
//local variable
int total = 0;
//if they checked off radiator to add 30
if (radiatorCheckBox.Checked == true)
{
total += 30;
serviceTextBox.Text = total.ToString("c");
}
//if they checked transmission to add 80 dollars
if (transmissionCheckBox.Checked == true) //this is saying if "they check this" than it means this:
{
//adds 80 because that's how much transmissions cost
total += 80;
serviceTextBox.Text = total.ToString("c");
return total;
}
else
{
//returns the total value
return total;
}
}
//private voids for all of the group boxes
private int Misc()
{
//local variables
int total = 0;
//if they checked off inspection to add 15 dollars
if (inspectionCheckBox.Checked == true)
{
total += 15;
serviceTextBox.Text = total.ToString("c");
}
//if they checked off muffler
if (mufflerCheckBox.Checked == true) //if they check off muffler it means this :
{
total += 100;
serviceTextBox.Text = total.ToString("c");
}
//Checked off tire rotation
if (tireCheckBox.Checked == true) //if they check off that they want the tire rotation it means this:
{
total += 20;
serviceTextBox.Text = total.ToString("c");
return total;
}
else
{
return total;
}
}
//this is for the Parts and Labor Group Box
private int OtherCharges()
{
int labor;
int parts;
int total = 0;
if (int.TryParse(laborTextBox.Text, out labor))
{
serviceTextBox.Text = labor.ToString("c");
total = labor;
return total;
}
if (int.TryParse(partsTextBox.Text, out parts))
{
partsLabel.Text = parts.ToString("c");
total = parts;
return total;
}
else
{
return total;
}
}
private decimal Tax()
{
//for the taxes on all of this
decimal addTax;
decimal tax = 0;
decimal parts;
decimal totalParts = 0;
if (decimal.TryParse(partsTextBox.Text, out parts))
{
totalParts = parts;
partsLabel.Text = totalParts.ToString("c");
parts = decimal.Parse(partsTextBox.Text);
tax = parts * 0.06m;
taxLabel.Text = tax.ToString("c");
return tax;
if (decimal.TryParse(taxOnPartLabel.Text, out addTax))
{
tax = totalParts * 0.06m;
taxOnPartLabel.Text = tax.ToString("c");
return tax;
}
else
{
return totalParts;
}
}
else
{
return tax;
}
}
//for the total
private decimal TotalCharges()
{
decimal total;
total = OilLubeCharges() + Flushes() + Misc() + OtherCharges() + Tax() + TotalCharges();
totalLabel.Text = total.ToString("c");
return total;
}
//the button for clearing out everything in the output Labels,radioButtons, and ect.
private void clearButton_Click(object sender, EventArgs e)
{
//to clear out everything on the project
oilCheckBox.Checked = false;
lubeCheckBox.Checked = false;
radiatorCheckBox.Checked = false;
transmissionCheckBox.Checked = false;
transmissionCheckBox.Checked = false;
inspectionCheckBox.Checked = false;
mufflerCheckBox.Checked = false;
tireCheckBox.Checked = false;
partsTextBox.Text = "";
laborTextBox.Text = "";
serviceTextBox.Text = "";
partsLabel.Text = "";
taxLabel.Text = "";
totalLabel.Text = "";
}
}
}
Link to comment
https://www.neowin.net/forum/topic/1279060-help-with-my-c-project/Share on other sites
12 answers to this question
Recommended Posts