Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Coin Counter
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
klutzedufus




PostPosted: Sat Nov 03, 2012 9:13 am   Post subject: Coin Counter

So I made this program in turing because I wanted to see how much money I had, and writing it down was too mainstream. And so this program was born.

Turing:


% program coin counter
% you push a button every time you add a certain coin,
% for example "l" is $1 (loonie) and it counts how much money you have.

var pennies, nickels, dimes, quarters, loonies, toonies : int := 0
var total : real
var change : int := 1
var file : int
var input : string (1)
open : file, "coins.txt", put
close : file
open : file, "coins.txt", get
loop
    exit when eof (file)
    get : file, pennies
    get : file, nickels
    get : file, dimes
    get : file, quarters
    get : file, loonies
    get : file, toonies
    exit
end loop
close : file

fcn zerocheck (x : int) : int
    var y : int := x
    if y < 0 then
        y += 1
    end if
    result y
end zerocheck

proc save
    open : file, "coins.txt", put
    loop
        put : file, pennies
        put : file, nickels
        put : file, dimes
        put : file, quarters
        put : file, loonies
        put : file, toonies
        put "SAVED"
        exit
    end loop
    close : file
end save

View.Set ("offscreenonly")
loop
    cls
    if hasch then
        getch (input)
        case input of
            label ' ' :
                change *= -1
            label 'l' :
                loonies += 1 * change
                loonies := zerocheck (loonies)
            label 't' :
                toonies += 1 * change
                toonies := zerocheck (toonies)
            label 'q' :
                quarters += 1 * change
                quarters := zerocheck (quarters)
            label 'd' :
                dimes += 1 * change
                dimes := zerocheck (dimes)
            label 'n' :
                nickels += 1 * change
                nickels := zerocheck (nickels)
            label 'p' :
                pennies += 1 * change
                pennies := zerocheck (pennies)
            label (KEY_ENTER) :
                save
                put "SAVED"
            label (KEY_ESC) :
                exit
            label :
        end case
    end if
    total := 2.00 * toonies + 1.00 * loonies + 0.25 * quarters + 0.10 * dimes + 0.05 * nickels + 0.01 * pennies
    if change = 1 then
        put "ADDING"
    else
        put "REMOVING"
    end if
    put "toonies: ", toonies, ", $", (2.00 * toonies) : 2 : 2
    put "loonies: ", loonies, ", $", (1.00 * loonies) : 2 : 2
    put "quarters: ", quarters, ", $", (0.25 * quarters) : 2 : 2
    put "dimes: ", dimes, ", $", (0.10 * dimes) : 2 : 2
    put "nickels: ", nickels, ", $", (0.05 * nickels) : 2 : 2
    put "pennies: ", pennies, ", $", (0.01 * pennies) : 2 : 2
    put "total: $", total : 2 : 2
    View.Update

end loop

Sponsor
Sponsor
Sponsor
sponsor
QuantumPhysics




PostPosted: Thu Nov 08, 2012 9:09 pm   Post subject: RE:Coin Counter

Um... Cool?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: