# A programming problem

The numbers of calories per gram of carbohydrate, fat and protein are 4, 9 and 4 respectively. Write a programme that requests the nutritional content of food and display the number of calories per serving.

• [code]
private function GetCalories()
dim i as integer
dim i2 as integer
dim i3 as integer
i = inputbox("How many grams of carbohydrates in a serving?")
i2 = inputbox("How many grams of fat in a serving?")
i3 = inputbox("How many grams of protein are there in a serving?")
msgbox "The calories per serving are " & (i + i2 + i3) & "."
end function
[/code]
Hope this helps!
You'll have 2 have some code 2 call the function though.
Insert this in the sub or function that is called when the user wants
the program 2 run.
[code]
Call GetCalories()
[/code]
[red]Dragon[/red][purple]storM[/purple]

: The numbers of calories per gram of carbohydrate, fat and protein are 4, 9 and 4 respectively. Write a programme that requests the nutritional content of food and display the number of calories per serving.
:

• : [code]
: private function GetCalories()
: dim i as integer
: dim i2 as integer
: dim i3 as integer
: i = inputbox("How many grams of carbohydrates in a serving?")
: i2 = inputbox("How many grams of fat in a serving?")
: i3 = inputbox("How many grams of protein are there in a serving?")
: msgbox "The calories per serving are " & (i + i2 + i3) & "."
: end function
: [/code]
: Hope this helps!
: You'll have 2 have some code 2 call the function though.
: Insert this in the sub or function that is called when the user wants
: the program 2 run.
: [code]
: Call GetCalories()
: [/code]
: [red]Dragon[/red][purple]storM[/purple]
:
: : The numbers of calories per gram of carbohydrate, fat and protein are 4, 9 and 4 respectively. Write a programme that requests the nutritional content of food and display the number of calories per serving.
: :
:
: I think the msgbox line should be
msgbox "The calories per serving are " & ((i*4) + (i2*9) + (i3*4)) & "."
in order to get the correct calculation.
or it would look nicer with the following lines before the msgbox line
i = i*4
i2 = i2*9
i3 = i3*4
hope this helps

Sam Draper
Illinois Secretary fo State
Dept of Information Technology
Distributed Applications Section