SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member lancewatson's Avatar
    Join Date
    Jul 2010
    Location
    Grand Rapids, Michigan, United States
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    FREE BASIC Function help

    ' I am working on this tip calculator program. I am trying to have the program give a message that depends on the amount of tip. 10%= ok, 15%=good, 20%=best


    'DECLARE FUNCTIONS
    declare sub display_welcome
    declare function main() as integer
    declare function input_Meal()as single
    declare function calc_Tip(as single)as single
    declare function calc_Tax(as single)as single
    declare function calc_Total(as single,as single,as single) as single
    declare function print_info(as single,as single,as single)as single

    Function Main() as integer
    dim vcalctip as single
    dim calctax as single
    dim calctotal as single
    dim mealprice as single

    dim Variablewelcome as string

    display_welcome

    Print variablewelcome
    print " this returned welcome"
    mealprice = Input_meal

    print " now we are going to CALL the Function Calc_Tip passing mealp"
    vcalctip = Calc_tip(mealprice)
    print " Calc Tip used the mealP and returned a tip"
    calctax = Calc_tax(mealprice)

    calctotal = Print_info(mealprice, vcalctip, calctax)
    print ;
    PRINT USING "$$##.##";


    return 0
    end function

    'this is the FUNCTION that is called from the main function
    sub display_welcome()
    Dim welcome as string
    welcome = "Welcome to the meal calculator program. "
    end sub

    function Input_meal () as single
    dim mealPrice as single
    Input "Please enter meal price $", mealPrice
    Print "here we called the Input_meal function"
    return mealPrice
    end function

    function Calc_tip ( mealprice as single) as single
    dim Thetotaltip as single

    print " CalcTip used mealp as input, and is returning the tip "
    thetotaltip = mealprice * .20
    print " Calc_tip function calculated the tip and returned it to main"
    return thetotaltip
    end function

    function Calc_tax (mealprice as single) as single
    dim calctax as single
    calctax = mealprice * .06
    return calctax
    end function

    function Calc_total (mealprice as single, calctip as single, calctax as single) as single
    dim calctotal as single
    calctotal = mealprice + calctip + calctax
    Print "Receives the three values and returns 1"
    return calctotal
    end function

    'why can I use mealprice here - when it was always mealp in the other functions?
    function Print_info (mealp as single, calct as single, ctax as single) as single
    print "The meal price is ";
    Print using "$$##.##"; mealp 'floating dollar sign
    print "The tip is ",
    Print using "$$##.##"; calct 'fixed dollar sign

    print "The tax is ",
    PRINT USING "$$##.##"; ctax
    'correction
    print "The total is ",
    PRINT USING "$$##.##"; mealp + calct + ctax





    return 0
    end function

    main()

    sleep
    end

  2. #2
    #titanic {float:none} silver trophy
    molona's Avatar
    Join Date
    Feb 2005
    Location
    from Madrid to Heaven
    Posts
    8,269
    Mentioned
    249 Post(s)
    Tagged
    1 Thread(s)
    I am not familiar with Free Basic although it looks very similar to Visual Basic (which is natural considering that both are BASIC based)

    Still, I don't see a question here... what is that you wanted to ask?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •