Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

A programming problem

nelisinelisi Member Posts: 7
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.

Comments

  • dragonstormdragonstorm Member Posts: 44
    [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.
    :

  • Sam DraperSam Draper Member Posts: 3
    : [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

  • Justin BibJustin Bib USAMember Posts: 0

    _______ / http://forcoder.org / free video tutorials and ebooks about // C Go PL/SQL Swift Ruby Scratch MATLAB Delphi Java C# Visual Basic .NET PHP Visual Basic Assembly Objective-C R Perl Python JavaScript C++ Dart Crystal Clojure Prolog Scheme COBOL Fortran Apex Logo Rust Erlang Awk D Scala ML Julia VBScript Lua ABAP Bash F# SAS FoxPro Transact-SQL Hack LabVIEW Ada Lisp Alice Kotlin // __________

Sign In or Register to comment.