Archived

This topic is now archived and is closed to further replies.

Zach Parise

C# Programming Help

16 posts in this topic

Hey guys im having a little bit of trouble doing some C# coding right now and cant really finish this assignment just having a bit of trouble writing this code

heres the question:

A nutritionist who works for a fitness club helps memebers by evaluating their diets.As part of her evaluation, she asks members for the number of fat grams and carbohyrdrae grams that they consume in a day. Then, she calculates the number of calories that results from the fat using the following formula:

Calories from fat = fat grams x 9

Next, she calculates the number of calories that result from the carbohydrates using the following formula:

Calories from Carbs = Carbs grams x 4

Create an application that will make these calculations. In the application, you should have the following methods:

FATCALORIES - this method should accept a number of fat grams as an argument and return the number of calories from that amount of fat.

CARBCALORIES- this method should accept a number of carbohydrate grams as an argument and return the number of calories from that amount of carbohydrate.

Any help would be appreciated :(

0

Share this post


Link to post
Share on other sites

So you can set up a function that takes in a interger variable fatgrams and return the type double fat calories.

so something like. You should be able to look up the syntax of how to declare a function.

some ideas:

double fatcalories = fatgrams x9;

return fatcalories;

0

Share this post


Link to post
Share on other sites

Well, for starters you could say what exactly you are having trouble with. The assignment is simple enough that no general help can be given without basically doing it for you.

0

Share this post


Link to post
Share on other sites

So you can set up a function that takes in a interger variable fatgrams and return the type double fat calories.

so something like. You should be able to look up the syntax of how to declare a function.

some ideas:

double fatcalories = fatgrams x9;

return fatcalories;

0

Share this post


Link to post
Share on other sites

yea i know that part..

Just that Do i make a textbox so that the user can input the number then calculate it ?

0

Share this post


Link to post
Share on other sites

Shouldn't you be actually trying to learn this?

Well, for starters you could say what exactly you are having trouble with. The assignment is simple enough that no general help can be given without basically doing it for you.

0

Share this post


Link to post
Share on other sites

Shouldn't you be actually trying to learn this?

Exactly what happened in his other post /topic/336236-c-programming-help/">http://forum.canucks...ogramming-help/, we essentially wrote and tested it for him. There was no reply, so I have no idea if it actually helped or was simply copied/pasted and handed in.

I don't mind helping at all but he needs to be more descriptive, give some context around what you are doing so we can help without doing it for you (and maybe keep it in the same thread).

0

Share this post


Link to post
Share on other sites

You should clarify why you can't get it done as it is not at all clear. You should be specific about what exactly is holding you back.

Also, are you actually interested in programming? Or is this course just a technicality? If you actually want to learn how to program, Its not going to help you in the slightest if you don't figure these things out for yourself. if you want to be a programmer you have to have a healthy sense of self determination and intellectual curiosity. So if that is your intention, then the kind of help you need isn't getting an assignment done, its understanding how to do it.

0

Share this post


Link to post
Share on other sites

shouldn't that be part of the description of the assignment?

If it doesn't say I imagine for both fat and carbs you would want in input box, and an output box. Buttons are somewhat optional as you should be able to detect when the input box changes.

0

Share this post


Link to post
Share on other sites

I dont know how to lay out it on the Form , All i have is a calculate Button and Exit Button, Do i Need a Label ?

0

Share this post


Link to post
Share on other sites

heres my programming so far ....


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace WindowsFormsApplication1

{

	public partial class Form1 : Form

	{

		public Form1()

		{

			InitializeComponent();

		}

		private int fatCalories ( int fat)

		{

			return fat * 9;

		}

		private int carbCalories (int carbs)

		{

			return carbs * 4;

		}

		private void calculateButton_Click(object sender, EventArgs e)

		{

			int fatCALORIES;

			int carbCALORIES;

		    int fat

		    int carbs


			if(int.Parse(fatTextbox.Text))

			{

				fatCALORIES = fat * 9;



		}

	}

}

i tried tryParse, and Parse it does not work , it says its an error :s

I dont know where to go from here ..

heres my form !

bada.png

0

Share this post


Link to post
Share on other sites

A hockey forum probally isn't the best place for help.

Try asking a teacher or something.

0

Share this post


Link to post
Share on other sites

I don't see grams anywhere... input should be in grams. But you are on the right track over all.

0

Share this post


Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.