
-----------------------------------
bigman9
Thu Jan 20, 2011 7:47 pm

Help. Exiting program?
-----------------------------------
Hey i just made this program.
i want if so that when you hit 0 it exits the program. can someone help me. thanks:)



var pick: real:=0
var number: real
loop
put "Please enter the number that you wish to expariment with"
get pick

put "Select your choice of calculation:"
put "1) Square of the number"
put "2) Square root of the number"
put "3) Reciprocal of the number"
put "4) Cube of the number"
put "5) Cube root of the number"
put "0) Exit program"
get number

if number = 1 then
put pick*pick
end if

if number = 2 then
put sqrt(pick)
end if

if number = 3 then
put pick/(pick*pick)
end if

if number = 4 then
put pick*pick*pick
end if

if number = 5 then
%put pick^1/3
end if

if number = 0 then
exit
end if
end loop

-----------------------------------
ProgrammingFun
Thu Jan 20, 2011 7:55 pm

RE:Help. Exiting program?
-----------------------------------
Enclose the whole program in a conditional loop which will exit if 0 is entered anywhere...

-----------------------------------
bigman9
Thu Jan 20, 2011 7:57 pm

RE:Help. Exiting program?
-----------------------------------
it didnt work:/

-----------------------------------
ProgrammingFun
Thu Jan 20, 2011 8:04 pm

RE:Help. Exiting program?
-----------------------------------
Do you want the program to exit if the first input is 0?

[syntax]
Ask for first number

if number != 0 

Display options

else choice = 0

then you if else conditions will automatically exit the program for you.

-----------------------------------
bigman9
Thu Jan 20, 2011 8:05 pm

RE:Help. Exiting program?
-----------------------------------
The second but i think i got it...



var pick: real:=0
var number: real
var chars : array char of boolean
put "Please enter the number that you wish to expariment with"
get pick
loop
put "Select your choice of calculation:"
put "1) Square of the number"
put "2) Square root of the number"
put "3) Reciprocal of the number"
put "4) Cube of the number"
put "5) Cube root of the number"
put "0) Exit program"
get number

if number = 1 then
put pick*pick
end if

if number = 2 then
put sqrt(pick)
end if

if number = 3 then
put pick/(pick*pick)
end if

if number = 4 then
put pick*pick*pick
end if

if number = 5 then
put pick**(1/3)
end if

if chars ('0') then
exit
end if
end loop

-----------------------------------
ProgrammingFun
Thu Jan 20, 2011 8:11 pm

RE:Help. Exiting program?
-----------------------------------

var pick : real := 0
var number : real
var chars : array char of boolean
put "Please enter the number that you wish to expariment with"
get pick
loop
    /*only show this menu if if pick is not 0
    otherwise, set number to 0*/
    put "Select your choice of calculation:"
    put "1) Square of the number"
    put "2) Square root of the number"
    put "3) Reciprocal of the number"
    put "4) Cube of the number"
    put "5) Cube root of the number"
    put "0) Exit program"
    get number

    if number = 1 then
        put pick * pick
    end if

    if number = 2 then
        put sqrt (pick)
    end if

    if number = 3 then
        put pick / (pick * pick)
    end if

    if number = 4 then
        put pick * pick * pick
    end if

    if number = 5 then
        put pick ** (1 / 3)
    end if

    if chars ('0') then
        exit
    end if
end loop


-----------------------------------
bigman9
Thu Jan 20, 2011 8:14 pm

RE:Help. Exiting program?
-----------------------------------
I want the menu to show so they see the option that 0 is to exit. then when they hit 0 then enter it exits the program?

-----------------------------------
bigman9
Thu Jan 20, 2011 8:17 pm

RE:Help. Exiting program?
-----------------------------------
but now when i click any other nymber it exits the program

-----------------------------------
Tony
Thu Jan 20, 2011 8:18 pm

RE:Help. Exiting program?
-----------------------------------
Simply throwing a question mark at the end of a sentence does not necessary turn it a question.

-----------------------------------
bigman9
Thu Jan 20, 2011 8:22 pm

RE:Help. Exiting program?
-----------------------------------
okaaay...How come when i click numbers 1-4 it closes the program wehn i put if chars ('0') then exit?

-----------------------------------
Tony
Thu Jan 20, 2011 8:24 pm

RE:Help. Exiting program?
-----------------------------------
Your program comes to the end via some other path.

-----------------------------------
bigman9
Thu Jan 20, 2011 8:25 pm

RE:Help. Exiting program?
-----------------------------------
can you please hook me with the correct code for the end then?:)

-----------------------------------
ProgrammingFun
Thu Jan 20, 2011 8:26 pm

RE:Help. Exiting program?
-----------------------------------

var pick : real := 0
var number : real
var chars : array char of boolean
put "Please enter the number that you wish to expariment with (0 is to exit)"
get pick
loop
    if pick != 0
        put "Select your choice of calculation:"
        put "1) Square of the number"
        put "2) Square root of the number"
        put "3) Reciprocal of the number"
        put "4) Cube of the number"
        put "5) Cube root of the number"
        put "0) Exit program"
        get number
    end if

    if pick = 0
        number = 0
    end if

    if number = 1 then
        put pick * pick
    end if

    if number = 2 then
        put sqrt (pick)
    end if

    if number = 3 then
        put pick / (pick * pick)
    end if

    if number = 4 then
        put pick * pick * pick
    end if

    if number = 5 then
        put pick ** (1 / 3)
    end if
    
     if number = 0
     exit
     end if
end loop
end loop 


-----------------------------------
bigman9
Thu Jan 20, 2011 8:28 pm

RE:Help. Exiting program?
-----------------------------------
4 errors

-----------------------------------
ProgrammingFun
Thu Jan 20, 2011 8:29 pm

Re: RE:Help. Exiting program?
-----------------------------------
4 errors

The logic is alright.
I have forgotten the turing syntax and there is an extra end loop at the end....

I was editing that but then you replied  :roll:

-----------------------------------
bigman9
Thu Jan 20, 2011 8:32 pm

RE:Help. Exiting program?
-----------------------------------
my bad, i fixed it with some thens. But it doesnt work. the 0 does notta

-----------------------------------
ProgrammingFun
Thu Jan 20, 2011 8:33 pm

RE:Help. Exiting program?
-----------------------------------
can you post the code?

-----------------------------------
bigman9
Thu Jan 20, 2011 8:34 pm

RE:Help. Exiting program?
-----------------------------------
yeah. okay but heres the thing. i want it to be so that the second input must be 0 for the program to exit













var pick : real := 0 
var number : real 
var chars : array char of boolean 
put "Please enter the number that you wish to expariment with (0 is to exit)" 
get pick 
loop 
    if pick = 0 then
        put "Select your choice of calculation:" 
        put "1) Square of the number" 
        put "2) Square root of the number" 
        put "3) Reciprocal of the number" 
        put "4) Cube of the number" 
        put "5) Cube root of the number" 
        put "0) Exit program" 
        get number 
    end if 

    if pick = 0 then
        number := 0 
    end if 

    if number = 1 then 
        put pick * pick 
    end if 

    if number = 2 then 
        put sqrt (pick) 
    end if 

    if number = 3 then 
        put pick / (pick * pick) 
    end if 

    if number = 4 then 
        put pick * pick * pick 
    end if 

    if number = 5 then 
        put pick ** (1 / 3) 
    end if 
    
     if number = 0 then
     exit 
     end if 
end loop

-----------------------------------
bigman9
Thu Jan 20, 2011 8:36 pm

RE:Help. Exiting program?
-----------------------------------
could my variable declarations be wrong?

-----------------------------------
ProgrammingFun
Thu Jan 20, 2011 8:48 pm

RE:Help. Exiting program?
-----------------------------------

if pick = 0 then /*