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

Username:   Password: 
 RegisterRegister   
 Help. Exiting program?
Index -> Programming, Turing -> Turing Help
Goto page 1, 2, 3  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh pageAdd this topic to your bookmarks (CTRL-D) View next topic
Author Message
bigman9




PostPosted: 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
 
Sponsor
Sponsor
Sponsor
sponsor
ProgrammingFun




PostPosted: 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...
 
bigman9




PostPosted: Thu Jan 20, 2011 7:57 pm   Post subject: RE:Help. Exiting program?

it didnt work:/
 
ProgrammingFun




PostPosted: 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.
 
bigman9




PostPosted: 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
 
ProgrammingFun




PostPosted: 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
 
bigman9




PostPosted: 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?
 
bigman9




PostPosted: 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
 
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
 
bigman9




PostPosted: 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?
 
Tony




PostPosted: Thu Jan 20, 2011 8:24 pm   Post subject: RE:Help. Exiting program?

Your program comes to the end via some other path.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
 
bigman9




PostPosted: 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
 
ProgrammingFun




PostPosted: 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
 
bigman9




PostPosted: Thu Jan 20, 2011 8:28 pm   Post subject: RE:Help. Exiting program?

4 errors
 
ProgrammingFun




PostPosted: 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
 
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh pageAdd this topic to your bookmarks (CTRL-D) View next topic

Page 1 of 3  [ 40 Posts ]
Goto page 1, 2, 3  Next
Jump to:   


Style:  
Search: