-
July 9th, 2013, 03:21 PM
#1
Have Mercy 1st Post Visual C#
I moderate a few forums..so I know how aggravating noobs are.
Anyway..
Trying to form a basic Calorie Counter App.. (Visual Studio 2010)
My issue is that it appears my methods are not being called properly, I simply need to accept user input, and call the method (a simple method that multiplies the user input * a variable) and then display that answer out into a label. For some reason all I am getting in the output label is the exact input the user enters.
Code:
Code:
namespace Calorie_Calculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Methods:
private double FatCalories(double Fat)
{
return Fat * 9.0;
}
private double CarbCalories(double Carb)
{
return Carb * 4.0;
}
private void fatCalloriesButton_Click(object sender, EventArgs e)
{
//Variables for Fat Carbs & Calories
double Fat, Calories;
//Get Number of FAT Grams
if (double.TryParse(fatTextBox.Text, out Fat))
{
//Calculate Calories from Fat:
Calories = FatCalories(Fat);
//Display Fat Calories:
outputLabel.Text = Fat.ToString("n1");
}
else
{
//Error Message:
MessageBox.Show("Enter a valid Number.");
}
}
private void carbCallorieButton_Click(object sender, EventArgs e)
{
//Variables:
double Carb, Calories;
if (double.TryParse(carbTextBox.Text, out Carb))
{
Calories = CarbCalories(Carb);
outputLabel.Text = Carb.ToString("n1");
}
else
{
MessageBox.Show("Enter a valid Number.");
}
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
Any thoughts as to why the heck this isnt working? Again.. just a noob here.
Last edited by Arjay; July 12th, 2013 at 02:30 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|