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

Username:   Password: 
 RegisterRegister   
 calculator error
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
con.focus




PostPosted: Thu Dec 02, 2004 6:15 pm   Post subject: calculator error

im making a calculator simple though every time when usinmg the divison function and the secound number is 0 is outputs an error ne way i can beat the programm to it by tell is to exit the function and output an error message if the secound number is 0 and the function being used is division
here's my code
code:
var inum1,inum2 : real
var ch :char
get inum1
get inum2
get ch
if ch = '/' then
put inum1 / inum2
elsif ch = '*' then
put inum1 * inum2
elsif ch = '-' then
put inum1 - inum2
elsif ch = '+' then
put inum1 + inum2
end if
Sponsor
Sponsor
Sponsor
sponsor
Mazer




PostPosted: Thu Dec 02, 2004 6:21 pm   Post subject: (No subject)

Just check to make sure that inum2 isn't equal to 0. If it's zero and they choose '/' then just don't do the operation. Try this in your if statement:

code:
if ch = '/' then
if inum2 not= 0 then
put inum1 / inum2
else
put "Can't divide by 0"
end if
%rest of if statement here
con.focus




PostPosted: Thu Dec 02, 2004 6:36 pm   Post subject: (No subject)

thx alot man i had to change a bit but the right idea i needed
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  [ 3 Posts ]
Jump to:   


Style:  
Search: