Computer Science Canada

Help. Exiting program?

Author:  bigman9 [ Thu Jan 20, 2011 7:47 pm ]
Post subject:  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

Author:  ProgrammingFun [ Thu Jan 20, 2011 7:55 pm ]
Post subject:  RE:Help. Exiting program?

Enclose the whole program in a conditional loop which will exit if 0 is entered anywhere...

Author:  bigman9 [ Thu Jan 20, 2011 7:57 pm ]
Post subject:  RE:Help. Exiting program?

it didnt work:/

Author:  ProgrammingFun [ Thu Jan 20, 2011 8:04 pm ]
Post subject:  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.

Author:  bigman9 [ Thu Jan 20, 2011 8:05 pm ]
Post subject:  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

Author:  ProgrammingFun [ Thu Jan 20, 2011 8:11 pm ]
Post subject:  RE:Help. Exiting program?

Turing:

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

Author:  bigman9 [ Thu Jan 20, 2011 8:14 pm ]
Post subject:  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?

Author:  bigman9 [ Thu Jan 20, 2011 8:17 pm ]
Post subject:  RE:Help. Exiting program?

but now when i click any other nymber it exits the program

Author:  Tony [ Thu Jan 20, 2011 8:18 pm ]
Post subject:  RE:Help. Exiting program?

Simply throwing a question mark at the end of a sentence does not necessary turn it a question.

Author:  bigman9 [ Thu Jan 20, 2011 8:22 pm ]
Post subject:  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?

Author:  Tony [ Thu Jan 20, 2011 8:24 pm ]
Post subject:  RE:Help. Exiting program?

Your program comes to the end via some other path.

Author:  bigman9 [ Thu Jan 20, 2011 8:25 pm ]
Post subject:  RE:Help. Exiting program?

can you please hook me with the correct code for the end then?Smile

Author:  ProgrammingFun [ Thu Jan 20, 2011 8:26 pm ]
Post subject:  RE:Help. Exiting program?

Turing:

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

Author:  bigman9 [ Thu Jan 20, 2011 8:28 pm ]
Post subject:  RE:Help. Exiting program?

4 errors

Author:  ProgrammingFun [ Thu Jan 20, 2011 8:29 pm ]
Post subject:  Re: RE:Help. Exiting program?

bigman9 @ Thu Jan 20, 2011 8:28 pm wrote:
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 Rolling Eyes

Author:  bigman9 [ Thu Jan 20, 2011 8:32 pm ]
Post subject:  RE:Help. Exiting program?

my bad, i fixed it with some thens. But it doesnt work. the 0 does notta

Author:  ProgrammingFun [ Thu Jan 20, 2011 8:33 pm ]
Post subject:  RE:Help. Exiting program?

can you post the code?

Author:  bigman9 [ Thu Jan 20, 2011 8:34 pm ]
Post subject:  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

Author:  bigman9 [ Thu Jan 20, 2011 8:36 pm ]
Post subject:  RE:Help. Exiting program?

could my variable declarations be wrong?

Author:  ProgrammingFun [ Thu Jan 20, 2011 8:48 pm ]
Post subject:  RE:Help. Exiting program?

Turing:

if pick = 0 then /*<----- this is supposed to be "not equals to"*/
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

Author:  RandomLetters [ Thu Jan 20, 2011 8:54 pm ]
Post subject:  Re: Help. Exiting program?

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


What is wrong here? Follow through the code and think about what it is doing.

Author:  bigman9 [ Thu Jan 20, 2011 8:55 pm ]
Post subject:  RE:Help. Exiting program?

it doesnt work....

i have this code now. the thiing is is that when i put if keys ('O')<---(thats a oh) it works. But it wont wont work if theres a ZERO there

Author:  bigman9 [ Thu Jan 20, 2011 8:56 pm ]
Post subject:  RE:Help. Exiting program?

var pick: real:=0
var number: real
var keys : array char of boolean
put "Please enter the number that you wish to expariment with"
get pick
loop
Input.KeyDown (keys)

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 keys ('O') then
exit
end if
end loop

Author:  ProgrammingFun [ Thu Jan 20, 2011 8:58 pm ]
Post subject:  RE:Help. Exiting program?

You still don't understand...
Why don't you try what I indicated in the last comment? Or maybe what RandomLetters suggested. (They are both the same thing)

Author:  RandomLetters [ Thu Jan 20, 2011 9:01 pm ]
Post subject:  Re: Help. Exiting program?

Quote:
if keys ('O') then
exit
end if
end loop


You're making things more complicated then they need to be.
If what you used for the other options worked, why not keep using the same thing?

Author:  bigman9 [ Thu Jan 20, 2011 9:02 pm ]
Post subject:  RE:Help. Exiting program?

i am doing an assignment. so the 0 has to be the second input

Author:  bigman9 [ Thu Jan 20, 2011 9:10 pm ]
Post subject:  RE:Help. Exiting program?

this is so frusterating!Sad

Author:  bigman9 [ Thu Jan 20, 2011 9:10 pm ]
Post subject:  RE:Help. Exiting program?

if someone can post the who correct program il give them all my bits

Author:  Tony [ Thu Jan 20, 2011 9:24 pm ]
Post subject:  Re: RE:Help. Exiting program?

bigman9 @ Thu Jan 20, 2011 9:10 pm wrote:
if someone can post the who correct program il give them all my bits

That is not what we do, and it would defeat the point of the assignment, don't you think?

Author:  bigman9 [ Thu Jan 20, 2011 9:27 pm ]
Post subject:  RE:Help. Exiting program?

ive donew the whole thing!!!! i just dont know how to exit it!!!!!!!!!!!!!!!!!!!!!

Author:  ProgrammingFun [ Thu Jan 20, 2011 9:36 pm ]
Post subject:  Re: RE:Help. Exiting program?

WHY DON'T YOU JUST DO WHAT I AM SAYING THEN!?!?!??!?!?!?!

ProgrammingFun @ Thu Jan 20, 2011 8:48 pm wrote:
Turing:

if pick = 0 then /*<----- this is supposed to be "not equals to"*/
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

Author:  Tony [ Thu Jan 20, 2011 9:39 pm ]
Post subject:  RE:Help. Exiting program?

Reading comprehension.

Author:  ProgrammingFun [ Thu Jan 20, 2011 9:44 pm ]
Post subject:  Re: RE:Help. Exiting program?

Tony @ Thu Jan 20, 2011 9:39 pm wrote:
Reading comprehension.

Laughing +1 for that....

Author:  bigman9 [ Thu Jan 20, 2011 9:48 pm ]
Post subject:  RE:Help. Exiting program?

you guys are assholes and no help at all. BUT I GOT IT SO FUCK U

Author:  ProgrammingFun [ Thu Jan 20, 2011 10:33 pm ]
Post subject:  Re: RE:Help. Exiting program?

bigman9 @ Thu Jan 20, 2011 9:48 pm wrote:
you guys are assholes and no help at all. BUT I GOT IT SO FUCK U

Or maybe you should just learn simple english...

Author:  RandomLetters [ Thu Jan 20, 2011 11:09 pm ]
Post subject:  RE:Help. Exiting program?

I lol'd.

Author:  TokenHerbz [ Fri Jan 21, 2011 3:12 am ]
Post subject:  RE:Help. Exiting program?

talkin' like a BIG man for a "9" year old? /lolz

They did infact give you the answer. You just never read it expecting them to SOURCE it for you.

Be respectful here, Or Don't be here at all.

Author:  ProgrammingFun [ Fri Jan 21, 2011 7:38 am ]
Post subject:  RE:Help. Exiting program?

lol Laughing

Author:  Coldkick [ Fri Jan 21, 2011 9:37 am ]
Post subject:  RE:Help. Exiting program?

Get a hold of yourself. They were helping. You just aren't taking the time to think it through yourself. If an input is 0 then have the program exit, else if the input is not 0, allow it to continue. It's not that hard.

Author:  2goto1 [ Fri Jan 21, 2011 10:05 am ]
Post subject:  RE:Help. Exiting program?

Teaching your peers can be very rewarding


: