-
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.
-
July 9th, 2013, 03:24 PM
#2
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.
-
July 9th, 2013, 03:52 PM
#3
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?]
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
July 12th, 2013, 02:33 PM
#4
Re: Have Mercy 1st Post Visual C#
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?
-
July 14th, 2013, 08:53 AM
#5
Re: Have Mercy 1st Post Visual C#
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
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
|