
-----------------------------------
pheonix3000
Mon Feb 17, 2003 11:28 am

help plz
-----------------------------------
This is sort of a banking thing. i am not able to get through it. It keeps giving me errors at elsif iNum. Plz help me. any more stuff that i can add.
thx.

var iBalance : int := 0
    var iDeposit : int
    var iWithdraw :int
    var iTotald : int := 0
    var iTotalw : int:= 0
    var again : string (1)
    var leave : string (1)
    var iNum : int
    loop
    put "Please enter a number greater than -500"
    get iNum
        if iNum > 0 then
            iDeposit := iDeposit + iNum
            iTotald := iTotald + 1
            iBalance := iBalance + iDeposit
         elsif iNum < 0 then
            iWithdraw := iWithdraw -1
            iTotalw := iTotalw + 1
            iBalance := iBalance - iWithdraw
         elsif iNum:= 0 then 
            put "You have deposited" , iDeposit
            put "your Total Deposits are " , iTotald
            put "you have withdrawn" , iWithdraw
            put "your Total Withdraws are " , iTotalw
            put "your balance is" , iBalance
         end if
     put "Go again (y/n)"
     getch (again)
     exit when again = "n" or again = "N"
     put "exit (y/n)?"
     getch (leave)
     exit when leave  = "y" or leave = "Y"
  end loop

-----------------------------------
Dan
Mon Feb 17, 2003 11:52 am

= not :=
-----------------------------------
there are a few things wrong.

1st in the part 


elsif iNum := 0 then


it needs to be = not :=


elsif iNum = 0 then



2nd you need to have iDeposit set to something (initialize) if you are going to add to it.

3rd you need to do initialize(set initial value) iWithdraw too or you will get a simliare error.

i dont think this progame is doing what it is suppost to do yet. it may help if you tell us more about what it is suppost to do.

-----------------------------------
pheonix3000
Mon Feb 17, 2003 1:34 pm


-----------------------------------
yeah, its is like the banking thing. Where you make all the transcations thingi. k here is the thing that works. i want to make a few modifications . like i want the beginnning part ie from the welcome to entering 0 to be there always and i want the rest of it to clear. i dont know where to put the cls . And in the final answer how do i make the withdraws to be positive.

var iBalance : int := 0
    var iDeposit : int := 0
    var iWithdraw :int := 0
    var iTotald : int := 0
    var iTotalw : int:= 0
    var again : string (1)
    var iGrandt : int := 0 
    var iNum : int
    
    put "-|-Welcome. To deposit money enter positive numbers and to withdraw enter negative numbers"
    put "When finished your transcations, you can view your balances by entering the number as 0"
    put "Your current transcations are:"
    put "Your balance is : ", iBalance
    put "You have deposited : ", iDeposit
    put "You have withdrawn : ", iWithdraw
    put "Your total Deposits : ", iTotald
    put "Your Total withdraws : ", iTotalw
    put "Your GrandTotal is :", iGrandt
    put ""
    put "You may begin your transcations"
        loop
            put ""
            put "Please enter a number: "
            get iNum
            cls
            iGrandt := iTotald + iTotalw
                if iNum > 0 then
                    iDeposit := iDeposit + iNum
                    iTotald := iTotald + 1
                    iBalance := iBalance + iDeposit
                    put "You have deposited $ ", iDeposit
                    put ""
                else            
                    iWithdraw := iWithdraw -1
                    iTotalw := iTotalw + 1
                    iBalance := iBalance - iWithdraw
                    put "you have withdrawn $ ", iWithdraw 
                end if
                        if iNum = 0 then             
                            put "You have deposited " , iDeposit
                            put "your Total Deposits are " , iTotald
                            put "you have withdrawn" , iWithdraw
                            put "your Total Withdraws are " , iTotalw
                            put "your balance is " , iBalance
                            put "your Grand Total is" ,iGrandt
                        end if
            put ""
            put "Would you like to make another Transaction. (y/n)?"           
            getch (again)
            exit when again = "n" or again = "N" 
            cls
        end loop

-----------------------------------
pheonix3000
Mon Feb 17, 2003 2:30 pm


-----------------------------------
i was also wondering how to make the entire background to be black and the text to be green. Can u change the font of text ??

-----------------------------------
Tony
Mon Feb 17, 2003 2:34 pm


-----------------------------------
you can put the first part into a procedure and call that when you need it..

such as

procedure money()
put "tony is cool"
end money


then you can run all the code inside that just by calling money()

as for the cls, you put that first, then output all the information after that...

such as


loop
cls
money()
%input...


-----------------------------------
pheonix3000
Mon Feb 17, 2003 2:38 pm


-----------------------------------
Yeah, but we didnt learn about the procedures and functions yet. So i have to stick to the long way, i wantd to ask you something. has anyone made anh program on Logo that like there is a turtle on the screen and you move it by giving commands?

-----------------------------------
Tony
Mon Feb 17, 2003 3:24 pm


-----------------------------------
yes, you should have used out "forum search" function :wink:

http://www.compsci.ca/bbs/viewtopic.php?t=295

-----------------------------------
pheonix3000
Tue Feb 18, 2003 10:01 am


-----------------------------------
I was wondering.. how would you rotate an object. like in turing version 3, if i have to rotate an object to the right of 90 degrees how would i do that. Do u have to work with the x and y coordinates? or is there any special " for it code". if there isnt then what's the "format" code for doing so.

-----------------------------------
Tony
Tue Feb 18, 2003 10:58 am


-----------------------------------
that depends on the object you want to rotate... and what you need to do that for.

Often you can just rotate your image at w/e angles you need before you load your program and then use one of those angles. (Might not work if you need very detailed rotations).

-----------------------------------
pheonix3000
Tue Feb 18, 2003 11:08 am


-----------------------------------
i didnt understand what you said, but it is for a program, where i am supposed to move a character depending on what the user says -- you know one of those chr (). yeah i wanted to rorate them to a 90 degrees

-----------------------------------
Tony
Tue Feb 18, 2003 12:43 pm


-----------------------------------
< ^ > v

use those to rotate your object.

-----------------------------------
pheonix3000
Wed Feb 19, 2003 9:49 am


-----------------------------------
can u give an example?

-----------------------------------
Tony
Wed Feb 19, 2003 9:55 am


-----------------------------------
umm...

put "^"

? or what do you mean?

if its facing up, you use ^ if right its > if down its v if left its <

depending on the location your character is fasing, you output different symbols.

because you can't take a "T" and rotate that :?

-----------------------------------
pheonix3000
Wed Feb 19, 2003 12:35 pm


-----------------------------------
i am not sure whether this is the correct thing or not. i tried to the way u told but it didnt quite work

        var sCommand : string 
        var sFwd : string := "f" 
        var sLft: string := "l" 
        var sRght : string:= "r" 
        var iDst : int         
        var sQuit : string := "q" 
        var x : int := 15
        var y : int := 15
        var direction : int := 0

        loop 
            locate(round(y),round(x)) 
                put "|"
            locate(1,1) 
            put "please enter a command" 
                get sCommand 
            if sCommand = sFwd then 
                put "Please enter a distance" 
                get iDst 
                y := y - iDst 
                put "|" , y ,x
            elsif sCommand = sRght then
                get sCommand
                put "-"
            elsif sCommand = sLft then
                put "|"            
            end if 
            cls 
            
        end loop 

-----------------------------------
pheonix3000
Wed Feb 26, 2003 11:14 am


-----------------------------------
hi. I wanted to know how to code  this program. k the program is about a parking garage. k ur input he day, the time u have entered, and how many MINUTES you have parked and whether the user has a pass or not. then you would calculate :  $3.00 for every !/2 hr , $25.00 fpr daily maximum, $8.50 if u have a pass, $8.00 if time id after 6 pm and $7.00 on sunday. try to give me a pieceof code. for ex. 

day: thursday
time entered : 9.00
time parked : 153 minutes

u have to calcuate the the price.

reply soon,

-----------------------------------
Tony
Wed Feb 26, 2003 1:03 pm


-----------------------------------
that sounds too much like a homework assigment

let me remind you that we will NOT do your assigments for you (unless you gonna pay us... send me an email then :wink:)

-----------------------------------
pheonix3000
Thu Feb 27, 2003 4:04 am


-----------------------------------
Actually its not an homework assignment. i dont usually like to ask for the entire code cuz, what's the point of taking computer courses. neways, i tried to do a part of it and it goes something like this. it works but i want to round of the price. so that the ouput would be like $18.00. i tried a few things, but it kept giving me errors. also i would like to know how would i know that it is PM or Am when the time is given in 24 hr/.

var day : string (9)
var rtime : real
var totalmin : real
var pass : string (1)
var Price : real

put "Please enter the day: "
get day
put ""
put "Please enter the time entered : "
get rtime
put ""
put "Please enter the total minutes parked :"
get totalmin
totalmin:=(totalmin / 60)
put ""
put "Do u have a pass? "
get pass

if day = "Monday" or day = "Tuesday" or day = "Wednesday" or day =  
"Thursday" or  day = "Friday" or day = "Saturday" then
Price := ((totalmin + rtime) / 2)  * 3.00
put "Price" :5  
end if

***ITS NOT AN HW assignment****

-----------------------------------
Tony
Thu Feb 27, 2003 5:58 am


-----------------------------------
strange... I remember having a homework assigment just like this one :?

anyway, you can round using round() or ceil(). 2nd one will round it up, so 0.1 will round to 1. floor() rounds down.

on a 24 hours system, 00 is midnight, 12 is noon and 24 is midnight again. :?

So AM is 0 to 12 and PM is 12 to 24.

-----------------------------------
pheonix3000
Fri Feb 28, 2003 7:35 am


-----------------------------------
While converting 111111 in to decimal the answer is 31. that is the input is an interget, but if the user enters a srting like "a" along with the binary numbers how would you code that?

-----------------------------------
pheonix3000
Fri Feb 28, 2003 7:35 am


-----------------------------------
While converting 111111 in to decimal the answer is 31. that is the input is an interget, but if the user enters a srting like "a" along with the binary numbers how would you code that?  :?:

-----------------------------------
Tony
Fri Feb 28, 2003 7:59 am


-----------------------------------
you can convert string to integer using strint()

-----------------------------------
pheonix3000
Sat Mar 01, 2003 7:45 am


-----------------------------------
i am not able to find the error. when u run it enter the data as 
day : Monday
Time Entered : 9.00
Total mintues parked : 153
Pass: Y 
and then next time put pass as N
when pass is no then the price should come out as $18.00 and when pass is "N' then then the price should come out as $8.50.
i am not able to get that.


var day : string (9)
var rtime : real
var totalmin : real
var pass : string (1)
var Price : real

put "Please enter the day: "
get day
put ""
put "Please enter the time entered : "
get rtime
put ""
put "Please enter the total minutes parked :"
get totalmin
put ""
put "Do u have a pass? "
get pass
if day = "Monday" or day = "Tuesday" or day = "Wednesday" or day =
        "Thursday" or day = "Friday" or day = "Saturday" and pass = "N" then
    totalmin := totalmin / 60
    Price := round ( (totalmin + rtime) / 2) * 3.00
    put "Price ", Price, ".00"
elsif day = "Monday" or day = "Tuesday" or day = "Wednesday" or day =
        "Thursday" or day = "Friday" or day = "Saturday" or day = "Sunday"
        and pass = "Y" then
    Price := 8.500
    put "Price ", Price
end if

-----------------------------------
pheonix3000
Sun Mar 02, 2003 11:34 pm


-----------------------------------
i didnt get you on that strint () command. can u give me an example? it works fine when the user just enters the binary numbers, but as soon as the user enters a string with the binary numbers it gives an error. 
ex. a01010.
what would be the decimal answer?
whereas for 111111 the decimal answer is 31.

-----------------------------------
Tony
Mon Mar 03, 2003 12:28 am


-----------------------------------
you should get rid of non numeric characters first. Ether an ifstatment inside a loop or you can use index().

I'm not sure on how it works, but I think that index("abcdefghijklmnopqrstuvwxyz",i) will return a an index value of any of those letters... so if its more then 0, then its an invalid input. You should check the syntax in turing help file though.

-----------------------------------
pheonix3000
Wed Mar 05, 2003 7:11 pm


-----------------------------------
if u want to put the output statements in the horizontal order like this:

Day           Time entered      Minutes parked      Pass          Price 
Mon               0900                     153                 N           $18.00.


How would you do that? :?

-----------------------------------
Tony
Wed Mar 05, 2003 7:32 pm


-----------------------------------
ether with locate(row,column)

or

put name:10

where :10 means its 10 characters long so more spaces will be added to output to align

for floatpoint numbers its
num:2:10 where first :2 is number of decimal spaces and :10 as above

-----------------------------------
pheonix3000
Mon Mar 17, 2003 6:26 pm


-----------------------------------
case statements. how do u use the commands. like i sort of know how to do it, but i keep getting errors:

case "round" of
x := round (x)
put x
end case
end loop

-----------------------------------
Tony
Mon Mar 17, 2003 6:35 pm


-----------------------------------

case mark of
            label 9, 10 :   put "Excellent"
            label 7, 8 :        put "Good"
            label 6 :       put "Fair"
            label :     put "Poor"
        end case


so in your case   :lol: 


case command of
            label "round":   x:= round(x)
end case


-----------------------------------
Dan
Mon Mar 17, 2003 6:40 pm


-----------------------------------
that way to use case is:


var mark:int

put "put in your mark(10-1): "..
get mark

case mark of
            label 9, 10 :   put "Excellent"
            label 7, 8 :        put "Good"
            label 6 :       put "Fair"
            label :     put "Poor"
end case


you whode not use the case statment the way you are. the case stame wroks a lot like the if but it takes a varible like mark in the expalem abouve and then compares it to other posiable vlauses and if it maches it runs the comands in that label.

for any one that cares the case stament in turing is much liike the swich stament in c & c++.

-----------------------------------
Dan
Mon Mar 17, 2003 6:40 pm


-----------------------------------
dam, you posted befor me tony  :cry:

-----------------------------------
pheonix3000
Mon Mar 17, 2003 7:33 pm


-----------------------------------
k i didnt understand what the label was for. can u do it for the example i gave ????
k the below code. there is nothing wrong with. but just try it out. what i want is how can i keep the menu of operations as it is , in the sense that i want it to appear all the time but the input for calcualtion and the number should repeat and after the answer is ouputed, i want to clear the screen. such a way that the menu is as it is. i tried to put "loop" different places, didnt work. when i put cls anywhere the whole sceen excpept the input statemets remain on the sceen. that's not what i want. plz help.

var x : real
var y : real
var calc : int
var again : string (1)
var temp : real
View.Set ("graphics:450;500")
colorback (22)
cls
color (White)

    put ""
    put "           Square Root of ----------> ", "1"
    put ""
    put "           Absolute value ----------> ", "2"
    put ""
    put "           Round          ----------> ", "3"
    put ""
    put "           Addition       ----------> ", "4"
    put ""
    put "           Subtraction    ----------> ", "5"
    put ""
    put "           Division       ----------> ", "6"
    put ""
    put "           Multiplication ----------> ", "7"
    put ""
    put "           Div            ----------> ", "8"
    put ""
    put "           Mod            ----------> ", "9"
    put ""
    put "           **             ----------> ", "10"
    put ""
    put "--------------------------------------------------------"
    loop
        put "Press the number for desired calculation :"
        get calc
        put ""
        put "Please enter a number to calculate"
        get x
        temp := x
        put ""
        if calc = 3 then
            x := round (x)
            put x
        elsif calc = 1 then
            x := sqrt (x)
            put "The square root of", temp, "is", 
        elsif calc = 2 then
            x := abs (x)
            put x
        elsif calc = 4 then
            put "Please enter another number to calculate"
            get y
            x := x + y
            put x
        elsif calc = 5 then
            put "plese enter another number"
            get y
            x := x - y
        elsif calc = 6 then
            put "plese enter another number"
            get y
            x := x / y
        elsif calc = 7 then
            put "plese enter another number"
            get y
            x := x * y
        elsif calc = 8 then
            put "plese enter another number"
            get y
            x := x div y
        elsif calc = 9 then
            put "plese enter another number"
            get y
            x := x mod y
        elsif calc = 10 then
            put "plese enter another number"
            get y
            x := x ** y
            put "Do u want to go again (y/n)?"
            getch (again)
            exit when again = "y" or again = "Y"
        end if
    end loop

-----------------------------------
Asok
Mon Mar 17, 2003 7:39 pm


-----------------------------------
what I would reccomend is you redraw your menu or you do a Draw.FillBox over the results beneath that line.

-----------------------------------
pheonix3000
Mon Mar 17, 2003 7:41 pm


-----------------------------------
how do i do that. how would i frame my commands?

-----------------------------------
Asok
Mon Mar 17, 2003 8:03 pm


-----------------------------------
var x : real 
var y : real 
var calc : int 
var again : string (1) 
var temp : real 
View.Set ("graphics:450;500") 
colorback (22) 
cls 
color (white) 

put "" 
put " Square Root of ----------> ", "1" 
put "" 
put " Absolute value ----------> ", "2" 
put "" 
put " Round ----------> ", "3" 
put "" 
put " Addition ----------> ", "4" 
put "" 
put " Subtraction ----------> ", "5" 
put "" 
put " Division ----------> ", "6" 
put "" 
put " Multiplication ----------> ", "7" 
put "" 
put " Div ----------> ", "8" 
put "" 
put " Mod ----------> ", "9" 
put "" 
put " ** ----------> ", "10" 
put "" 
put "--------------------------------------------------------" 
loop 
locate (23,1)
put "Press the number for desired calculation :" 
get calc 
put "" 
put "Please enter a number to calculate" 
get x 
temp := x 
put "" 
if calc = 3 then 
x := round (x) 
put x 
elsif calc = 1 then 
x := sqrt (x) 
put "The square root of", temp, "is", x
elsif calc = 2 then 
x := abs (x) 
put x 
elsif calc = 4 then 
put "Please enter another number to calculate" 
get y 
x := x + y 
put x 
elsif calc = 5 then 
put "plese enter another number" 
get y 
x := x - y 
elsif calc = 6 then 
put "plese enter another number" 
get y 
x := x / y 
elsif calc = 7 then 
put "plese enter another number" 
get y 
x := x * y 
elsif calc = 8 then 
put "plese enter another number" 
get y 
x := x div y 
elsif calc = 9 then 
put "plese enter another number" 
get y 
x := x mod y 
elsif calc = 10 then 
put "plese enter another number" 
get y 
x := x ** y 
put "Do u want to go again (y/n)?" 
getch (again) 
exit when again = "y" or again = "Y" 
end if 
Draw.FillBox (0,0,400,100,22)
end loop

I decided to do it for you, notice your second half now works through locates, and the box is drawn over it at the end of the loop.

-----------------------------------
pheonix3000
Mon Mar 17, 2003 9:42 pm


-----------------------------------
Thanks a lot  :D . but i do get some mistakes. like when i start with addition and with i go back to the first one, it also askes me for the second number and as a result i get 2 answers. how would i frame the "if's" if i have to say that if calc is 1 ,2 and 3 then do the first three calcualtions and the rest to ask for the second number?

-----------------------------------
Asok
Mon Mar 17, 2003 10:43 pm


-----------------------------------
well I can't do the whole thing for you ;)

you should be able figure that one out on your own

-----------------------------------
pheonix3000
Thu Mar 20, 2003 10:35 pm


-----------------------------------
I am trying to figure out how to draw a diamond using "*" like i got how to draw a box, and a triangle.  but i am getting stuck in the diamond shape.
Can u also give me some pointers on how can i make hollow patterns.like
*****
*     *
*     *
*     *
*****

var n : int
var d : int
var count : int := 0
var size : int


put "Square : 1"
put "Triangle : 2"
put "Diamond  : 3"

put "Please enter the type you want"
get n
if n = 1 then
    loop
        put "Please enter the size"
        get size
        exit when size < 21 and size > 1
    end loop
    loop
        for i : 1 .. size
            put "*" ..
        end for
        count := count + 1
        exit when count = size
        put ""
    end loop
end if
if n = 2 then
    loop
        put "Please enter the size"
        get size
        exit when size < 21 and size > 1
    end loop
    loop
        count := count + 1
        for i : 1 .. count
            put "*" ..
        end for
        exit when count = size
        put ""
    end loop
end if
if n = 3 then
    loop
        put "Please enter the size"
        get size
        exit when size < 21 and size > 1
    end loop

    for decreasing i : count .. size by 1
        put " " ..
        loop
            count := count + 1
            put "*" ..
            exit when count > size
        end loop
        put ""
    end for
end if

-----------------------------------
Tony
Thu Mar 20, 2003 10:52 pm


-----------------------------------
...*
..***
.*****
*******
.*****
..***
...*

see the pattern? number of spaces (. in example) decreases by 1 each line until 0 and number of * increase by 2.

when it reaches middle (number of spaces = 0) process revenses.

initial number of spaces will determine the size

-----------------------------------
pheonix3000
Thu Mar 20, 2003 10:56 pm


-----------------------------------
k i sort of get it. not competly though. Is this what u meant ?
if n = 3 then
    loop
        put "Please enter the size"
        get size
        exit when size < 21 and size > 1
    end loop

    for decreasing i : " " .. 0 by 1
        put "*" ..
        if i = 0 then
            for i : " ".. 0 by 1            
            put "*" ..
            exit when count > size
            count := count + 1
        end loop
        put ""
    end for
end if

-----------------------------------
Asok
Fri Mar 21, 2003 12:37 am


-----------------------------------
It would help if ur sample code worked, too many things wrong in it for me to attempt to decode it all. Test the code out for yourself please before you post it. Be sure to include all variable declarations to make it easier. We are trying to help you, but we need the tools to do it properly ;)

-----------------------------------
pheonix3000
Fri Mar 21, 2003 8:46 pm


-----------------------------------
k here it is. The n = 3 is the diamond part. the first 2 work but not the third one. 

var n : int
var d : int
var count : int := 0
var size : int


put "Square : 1"
put "Triangle : 2"
put "Diamond  : 3"

put "Please enter the type you want"
get n
if n = 1 then
    loop
        put "Please enter the size"
        get size
        exit when size < 21 and size > 1
    end loop
    loop
        for i : 1 .. size
            put "*" ..
        end for
        count := count + 1
        exit when count = size
        put ""
    end loop
end if
if n = 2 then
    loop
        put "Please enter the size"
        get size
        exit when size < 21 and size > 1
    end loop
    loop
        count := count + 1
        for i : 1 .. count
            put "*" ..
        end for
        exit when count = size
        put ""
    end loop
end if
if n = 3 then
    loop
        put "Please enter the size"
        get size
        exit when size < 21 and size > 1
    end loop

    for decreasing i : 20 .. size by 1
        put " " ..
        loop
            count := count + 1
            put "*" ..
            exit when count > size
        end loop
        put ""
    end for

end if

-----------------------------------
Tony
Fri Mar 21, 2003 9:05 pm


-----------------------------------
wow dude, you got it all wrong... I mean look at your output, thats nowhere close!


for decreasing i : size .. 0 by 1
    for i2:0..i
    put " "..
    end for
    for i3:1.. size - i * 2
    put "*"..
    end for
    put ""
end for 


that outputs your first half. now for the bottom half, you just revese it. I'd like you to figure that part out yourself.

-----------------------------------
Prince
Sat Mar 29, 2003 3:24 pm


-----------------------------------
wow... how do u plan on passing the gr 11 comp sci course if u cant figure anythin out on ur own? ur practically askin the mods to do every project for u... if u get any good marks u should giv tony all the credit

-----------------------------------
Tony
Sat Mar 29, 2003 3:33 pm


-----------------------------------
thx PrInCe_... but if I was getting marks for helping others, my compsci mark would be in 4 digits already  :shock:

-----------------------------------
azndragon
Sun Mar 30, 2003 9:43 am


-----------------------------------
wow... how do u plan on passing the gr 11 comp sci course if u cant figure anythin out on ur own? ur practically askin the mods to do every project for u... if u get any good marks u should giv tony all the credit

Some people need some time to develop their skills. I used to ask tons of questions, but now, I'm pretty much self-reliant, and basically go through the help file, and use some examples.
