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.
Re: Have Mercy 1st Post Visual C#
Perhaps I need to elaborate a bit more..rather than being so vague.
The app simply needs to use the methods to calculate the number of callories from fat grams as well as from carb grams.
Re: Have Mercy 1st Post Visual C#
This is the visual c++ forum, not the c# one! Please re-post to the c-sharp programming forum. Also, when posting code please use code tags. Go Advanced, select code and click '#'.
[moderator - could you move please?]
Re: Have Mercy 1st Post Visual C#
Quote:
Originally Posted by
JeepNDave
Any thoughts as to why the heck this isnt working? Again.. just a noob here.
What isn't working? No values show up? The values are incorrect? What?
Re: Have Mercy 1st Post Visual C#
Quote:
Originally Posted by
JeepNDave
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.
You are passing the user input to the output label:
Code:
outputLabel.Text = Fat.ToString("n1");
You need to pass the calories value to the output lable:
Code:
outputLabel.Text = Calories.ToString("n1");
Kristof