Computer Science Canada My first calculator program... |
Author: | MysticVegeta [ Mon Nov 08, 2004 6:13 pm ] | ||
Post subject: | My first calculator program... | ||
My first calculator program. Please dont laugh...
|
Author: | cool dude [ Mon Nov 08, 2004 6:27 pm ] |
Post subject: | |
this is the wrong place to post something you did. this section is only for help. you should post in the turing submissions or source code. anyways nice calculator. a suggestion would be by error proofing it so if the user enters a letter instead of a number the calcuator could say error or say numbers only. good job! |
Author: | Tony [ Mon Nov 08, 2004 6:33 pm ] | ||
Post subject: | |||
why do you repeat conditions?
? |
Author: | Paul [ Mon Nov 08, 2004 6:40 pm ] |
Post subject: | |
lol, no one will laugh at urs after they see my poor first calculator. Rofl, it sux bad. It seemed like ages ago... lol ![]() http://www.compsci.ca/v2/viewtopic.php?t=3452 |
Author: | myob [ Mon Nov 08, 2004 9:27 pm ] |
Post subject: | |
would be better if u put in error trap for it. soon you will learn enough about error traps (u gonna be da master of it in grade 12) |
Author: | wtd [ Mon Nov 08, 2004 11:01 pm ] | ||
Post subject: | |||
As has been mentioned, there's no need to repeat conditions. Additionally, you should be using "elsif" and "else".
|
Author: | MysticVegeta [ Sun Nov 21, 2004 10:04 pm ] | ||
Post subject: | ---- Version 2 ---- | ||
thanks for your help people, i edited the program a lil bit and called it Version 2. I LIKE IT!!!
|
Author: | MattyGG [ Tue Nov 23, 2004 11:55 am ] |
Post subject: | |
It's better than the first one...but there should also be a way to quit the program when you want to...otherwise great job |
Author: | wtd [ Tue Nov 23, 2004 3:03 pm ] | ||||||||||||||||||||
Post subject: | |||||||||||||||||||||
Quote: put ""
put "Enter the first number:" var a : int get a put "" put "Enter the math function (+, -, *, /" put "s for sin, c for cos, t for tan" var s : string get s put "" put "Enter the second number" var d : int get d put "" put "....................................." Now, you have this, but how about we box it up in a procedure? We're doing output, so it should be a procedure. We're "getting" an "equation", so we'll call it...
We're getting information about "a" and "d", so those are the parameters for the procedure. We're also getting an "operator".
So, with those as parameters, we no longer need to declare them inside the procedure. Then of course, we can end the procedure.
So, we can now rewrite your program slightly. oh, and we'll simplify your conditionals.
Is redundant.
No, let's factor out some more code.
Can easily be in a separate procedure.
And we can factor out:
Into "evaluateEquation". Oh, and we can use a case statement.
So, now the code looks like:
leave it to your imagination to further factor this code down. ![]() |
Author: | Delos [ Tue Nov 23, 2004 4:40 pm ] | ||
Post subject: | |||
Quote:
Quote: Syntax arccos (r : real) : real Description The arccos function is used to find the arc cosine of a value. The result is given in radians. For example, arccos (0.5) is p / 3. Syntax arcsin (r : real) : real Description The arcsin function is used to find the arc sine of a value. The result is given in radians. For example, arcsin (0.5) is p / 6. Syntax arctan (r : real) : real Description The arctan function is used to find the arc tangent of a value. The result is given in radians. For example, arctan (1) is p / 4. ![]() MysticVegeta, take wtd's advice, it's good stuff it is. |
Author: | wtd [ Wed Nov 24, 2004 3:59 am ] | ||
Post subject: | |||
A further modification would involve using a record type to hold information about the equation:
|
Author: | MysticVegeta [ Fri Nov 26, 2004 7:28 am ] |
Post subject: | |
Thanks wtd... i am not upto record yet, i think i will shorten it using the code you posted above. And oh yea, my turing version is the old one, so the arcin and arctan functions are not supported. thanks for your advice. ![]() |