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

Username:   Password: 
 RegisterRegister   
 Help with spacing/alignment
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Shades




PostPosted: Wed Jun 06, 2007 11:34 am   Post subject: Help with spacing/alignment

So I have a project where I have to create a bank assigment, and I tried to allign all the demials, I currently have this (obviously for different parts of the program, but I'll just show one since it's the same for the other parts:

code:
color (116)
put "Opening Balance" : 40, "$ ", balances (pin_num) : 10 : 2


It alligns most values, although when I do it with bigger values it doesn't, example:
  • When I had the value 209900999, when it was displayed with the spacing above, it rounded it to 209901000.
  • Basically, when a 10, 9, 8, digit number is entered, the allignment doesn't work and it gets rounded


It works for all number with 7 or less digits, why's that, and any possible fixes?
Sponsor
Sponsor
Sponsor
sponsor
Shades




PostPosted: Wed Jun 06, 2007 11:46 am   Post subject: Re: Help with spacing/alignment

I forgot to put this in the first post, but I can't just have a big space between dollar sign and the number like this output that I got when I changed the 10 to 30:

code:

$                                    209900999.00
$                                           20.00


Has to output like so:

code:

$ 209900999.00
$        20.00


The largest value has to start beside the dollar sign, and the smaller values lign up the decimal places
Albrecd




PostPosted: Wed Jun 06, 2007 12:09 pm   Post subject: Re: Help with spacing/alignment

Hmm...
Your rounding problem doesn't occur when I try the code you gave me. Could you post more of your code? I think your variable is being changed elsewhere.
Shades




PostPosted: Wed Jun 06, 2007 7:06 pm   Post subject: Re: Help with spacing/alignment

Ok, here you go (the whole program):
Provided you have a txt file in the same folder as the turing file called "overdraft.txt" that says on one line "overdraft" and the next "nooverdraft"
And:
You have a txt file called "info.txt" that says:
"1234
12.75
9800
345.32
0101
985.04"

Turing:
%The 'c' variables are all counters

var pin : int
var pins : array 1 .. 6 of int
var balances : array 1 .. 6 of real
var filenum : int
var filenum2 : int
var pincount : int := 1
var balancecount : int := 2
var usrpin : int
var pincheck : boolean := false
var c : int := 0
var pin_num : int
var rlbalance : real
var do : string
var acntopt : array 1 .. 4 of string := init ("Withdraw money (WD)", "Deposit money (DEP)", "Pay your bills (BILL)", "See account activities (AAC)")
var amount1 : real
var overdraft : array 1 .. 2 of string
var accountnum : int
var counter : int := 0
var accounts : array 1 .. 3 of string
var blah : int
var done : boolean := false
var vals : array 1 .. 2, 1 .. 400 of string

proc askpin
    put "Please enter your pin number"
    get usrpin
end askpin

%Overdraft_Fun_Time
open : filenum2, "overdraft.txt", get
for w : 1 .. 2
    get : filenum2, overdraft (w)
end for
close : filenum2

%Get File Pins and Balances
open : filenum, "info.txt", get
loop
    get : filenum, pins (pincount)
    get : filenum, balances (balancecount)
    exit when eof (filenum)
    pincount += 2
    balancecount += 2
end loop
close : filenum

pincount := 1
balancecount := 1

%User enters pins, has 3 chances
loop
    askpin
    for k : 1 .. 6 by 2
        if usrpin = pins (k) then
            pincheck := true
            pin_num := k + 1
            rlbalance := balances (pin_num)
        end if
    end for
    c += 1
    exit when c = 3 or pincheck = true
end loop

%Figures out which account they picked
if usrpin = 1234 then
    accountnum := 1
elsif usrpin = 9800 then
    accountnum := 2
elsif usrpin = 0101 then
    accountnum := 3
end if

%Sets which accounts are overdraft and declares which accounts are overdraft/nooverdraft
accounts (1) := overdraft (1)
accounts (2) := overdraft (2)
accounts (3) := overdraft (1)

var c2 : int := 0

%Withdraw function and proc
var amount3 : real

function wd2 : real
    result rlbalance - amount3
end wd2

proc withdraw
    loop
        c2 += 1
        color (black)
        cls
        put "How much would you like to withdraw?"
        get amount3
        put " "
        if amount3 > rlbalance and accounts (accountnum) = "nooverdraft" then
            put "You are attempting to withdraw more money than is in your account"
            put "Your account may have meaning insufficient funds.."
            put "Your balance is $ ", rlbalance : 2, " please enter a valid amount"
        elsif amount3 < 0 then
            put "Please enter a valid amount"
        else
            exit
        end if
        if c2 > 5
                then
            put " "
            put "Are you dumb!?-Enter the proper amount, anything less than your current account!"
        end if
        delay (4000)
    end loop
    vals (1, c2) := "WD"
    vals (2, c2) := realstr (amount3, 0)
    rlbalance := wd2
    put "You have withdrawn, or not withdrawn (nooverdraft), your money;"
    put "Your current balance (updated) is: $ ", rlbalance : 2 : 2
    put " "
    put " "
    %delay (10000)
end withdraw

%Deposite function and proc
var amount2 : real

function dep : real
    result amount2 + rlbalance
end dep

var c4 : int := 0

proc deposite
    loop
        c4 += 1
        cls
        color (black)
        put "How much would you like to deposit?"
        get amount2
        if amount2 < 0 then
            put "Pleas enter a valid value"
            delay (3000)
        else
            exit
        end if
    end loop
    rlbalance := dep
    vals (1, c4 + 100) := "DEP"
    vals (2, c4 + 100) := realstr (amount2, 0)
    put "Your current balance (updated) is $ ", rlbalance : 2 : 2
    put " "
    put "You are being taken back to options menu.."
    %delay (10000)
end deposite

var ans2 : string

%Bill function and proc
function BILL : real
    result rlbalance - blah
end BILL

var check : array 1 .. 2 of boolean := init (true, true)

var c3 : int := 0

proc bill
    loop
        randint (blah, 1, 1337)
        cls
        color (black)
        put "Your bill to pay is $ ", blah : 2 : 2
        put "Do you want to pay it?(Y/N)"
        if rlbalance < blah and accounts (accountnum) = "nooverdraft" then
            put " "
            put "I'm sorry, you don't have enough money to pay your bill"
            check (1) := false
        else
            get ans2
        end if
        exit when ans2 = "N"
        c3 += 1
        if check (1) = true then
            rlbalance := BILL
        end if
        vals (1, c3 + 200) := "BILL"
        vals (2, c3 + 200) := intstr (blah)
        color (black)
        put " "
        put "Your current balance (updated) is $ ", rlbalance : 2 : 2
        put "You are being taken back to options menu.."
        %delay (10000)
        exit
    end loop
end bill

var check1 : boolean := false
var check2 : boolean := false

%Account Activities proc
proc aac
    cls
    color (black)
    %color (68)
    put " " : 18, "Account Activities"
    color (black)
    if balances (pin_num) > 0 /*or rlbalance > 0*/ then
        color (116)
        put "Opening Balance" : 40, "$ ", balances (pin_num) : 30 : 2
        check1 := true
    elsif balances (pin_num) <= 0 /*or rlbalance <= 0*/ then
        color (40)
        put "Opening Balance" : 40, "$ ", balances (pin_num) : 30 : 2
        check2 := true
    end if
    if c3 > 0 then
        for i : 1 .. c3
            color (black)
            put vals (1, i + 200) : 40, "$ ", strreal (vals (2, i + 200)) : 30 : 2
        end for
    end if
    if c2 > 0 then
        for z : 1 .. c2
            color (black)
            put vals (1, z) : 40, "$ ", strreal (vals (2, z)) : 30 : 2
        end for
    end if
    if c4 > 0 then
        for q : 1 .. c4
            color (black)
            put vals (1, q + 100) : 40, "$ ", strreal (vals (2, q + 100)) : 30 : 2
        end for
    end if
    put " "
    if rlbalance > 0 then
        color (116)
        put "Current Balance" : 40, "$ ", rlbalance : 30 : 2
    elsif rlbalance <= 0 then
        color (40)
        put "Current Balance" : 40, "$ ", rlbalance : 30 : 2
    end if
    color (black)
    put "You are being taken back to options menu.."
    %delay (10000)
end aac

var ans : string

%Proc that asks what user wants to do, then runs the corresponding proc
proc options
    loop
        cls
        color (black)
        put "Your current balance is $ ", rlbalance : 2 : 2
        put " "
        put "Choose one fo the following (type what's in brackets)"
        for l : 1 .. 4
            put acntopt (l)
        end for
        get do
        if do = "WD" then
            withdraw
        elsif do = "DEP" then
            deposite
        elsif do = "BILL" then
            bill
        elsif do = "AAC" then
            aac
        else
            color (black)
            put "Please type something valid"
        end if
        color (black)
        put " "
        put "Are you done all transactions?(Y to exit, N to go back to main menu)"
        get ans
        if ans = "Y" then
            done := true
        end if
        exit when done = true
    end loop
end options

%Runs program if their pin was valid, otherwise nothing happens
if pincheck = true then
    rlbalance := balances (pin_num)
    options
end if
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: