Have Mercy 1st Post Visual C#
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Have Mercy 1st Post Visual C#

  1. #1
    Join Date
    Jul 2013
    Location
    Chattanooga TN
    Posts
    2

    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.

  2. #2
    Join Date
    Jul 2013
    Location
    Chattanooga TN
    Posts
    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.

  3. #3
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,319

    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. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,220

    Re: Have Mercy 1st Post Visual C#

    Quote Originally Posted by JeepNDave View Post
    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?

  5. #5
    Join Date
    Sep 2006
    Posts
    31

    Re: Have Mercy 1st Post Visual C#

    Quote Originally Posted by JeepNDave View Post
    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center