Zigmund.Palffy Posted November 4, 2012 Share Posted November 4, 2012 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 Link to comment Share on other sites More sharing options...
Rhinogator Posted November 4, 2012 Share Posted November 4, 2012 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; Link to comment Share on other sites More sharing options...
butters Posted November 4, 2012 Share Posted November 4, 2012 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. Link to comment Share on other sites More sharing options...
Zigmund.Palffy Posted November 4, 2012 Author Share Posted November 4, 2012 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; Link to comment Share on other sites More sharing options...
Rhinogator Posted November 4, 2012 Share Posted November 4, 2012 yea i know that part.. Just that Do i make a textbox so that the user can input the number then calculate it ? Link to comment Share on other sites More sharing options...
Zigmund.Palffy Posted November 4, 2012 Author Share Posted November 4, 2012 No, its asking you for a parameter, not user input. Link to comment Share on other sites More sharing options...
InTheCrease Posted November 4, 2012 Share Posted November 4, 2012 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. Link to comment Share on other sites More sharing options...
Zigmund.Palffy Posted November 4, 2012 Author Share Posted November 4, 2012 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). Link to comment Share on other sites More sharing options...
butters Posted November 5, 2012 Share Posted November 5, 2012 Also on this assignment I cant seem to get it done. Link to comment Share on other sites More sharing options...
Zigmund.Palffy Posted November 5, 2012 Author Share Posted November 5, 2012 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. Link to comment Share on other sites More sharing options...
butters Posted November 5, 2012 Share Posted November 5, 2012 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. Link to comment Share on other sites More sharing options...
InTheCrease Posted November 5, 2012 Share Posted November 5, 2012 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 ? Link to comment Share on other sites More sharing options...
Zigmund.Palffy Posted November 5, 2012 Author Share Posted November 5, 2012 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 ! Link to comment Share on other sites More sharing options...
Zigmund.Palffy Posted November 5, 2012 Author Share Posted November 5, 2012 Any help guys ? Am i on the right track ? Link to comment Share on other sites More sharing options...
Peaches Posted November 5, 2012 Share Posted November 5, 2012 A hockey forum probally isn't the best place for help. Try asking a teacher or something. Link to comment Share on other sites More sharing options...
butters Posted November 5, 2012 Share Posted November 5, 2012 I don't see grams anywhere... input should be in grams. But you are on the right track over all. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.