E=Mc2 Program
Author |
Message |
evogre3n
|
Posted: Sun Apr 17, 2005 9:00 am Post subject: E=Mc2 Program |
|
|
Hey everyone.
This is the most recent assignement ivehad. Im just a begginer, starting out in turing.. and the assignment was on if structures and error traps etc.
Here is the code.
Check it out, give some feedback thanks a lot
code: |
%Nick
%April 15th 2005
%Ms. Dyke
%E=MC2 Program. This program will calculate either energy or mass based on the users input.
import GUI
var variableType, unitType, missingUnit, units : string
var answer, givenVariable : real
setscreen ("graphics: 500,600")
GUI.SetBackgroundColor (7)
colorback (7)
%Title
locate (1, 24)
color (0)
put "The E=MC2 Calculator" ..
%Introduction
locate (3, 1)
color (0)
put "Welcome to the E=MC2 Program. This program will calculate the missing variable in the equation E=MC2 based on your input foreither energy (e) or mass (m)"
%User Input
for x : 1 .. 99
locate (8, 1)
color (0)
put "Please enter your input variable."
put "Either 'e' for energy or 'm' for mass: " ..
get variableType
if variableType = "m" or variableType = "M" then
locate (10, 1)
color (0)
put "You have chosen mass, please continue"
unitType := "mass"
missingUnit := "energy"
units := "Joules"
locate (12, 1)
color (0)
put "Please enter the mass in Kg: " ..
get givenVariable
if givenVariable >= 0 then
locate (13, 1)
put "Thank you, please wait while your request is processed. "
exit
else
locate (7, 1)
color (12)
put "Your input for ", unitType, " was invalid, try again."
locate (12, 1)
put " "
locate (9, 40)
put " "
end if
elsif variableType = "e" or variableType = "E" then
locate (10, 1)
color (0)
put "You have chosen energy, please continue"
unitType := "energy"
missingUnit := "mass"
units := "Kg"
locate (12, 1)
color (0)
put "Please enter the energy in Joules: " ..
get givenVariable
if givenVariable >= 0 then
locate (13, 1)
put "Thank you, please wait while your request is processed. "
exit
else
locate (7, 1)
color (12)
put "Your input for ", unitType, " was invalid, try again."
locate (12, 1)
put " "
locate (9, 40)
put " "
end if
else
locate (7, 1)
color (12)
put "You have chosen incorrectly, please try again"
locate (9, 39)
put " "
end if
end for
%Processing
if variableType = "m" or variableType = "M" then
answer := givenVariable / (3 * (10 ** 8))
else
answer := givenVariable * (3 * (10 ** 8))
end if
%Output
locate (17, 1)
color (0)
put "Based on your input, the value of your missing variable, wich is ", missingUnit,", is equal to: " ..
color (14)
put answer , " ",units
%Ending Notes
locate (20, 1)
color (brightgreen)
put "Thank you for using The E=MC2 Calculator"
put "Look for our first public release in summer of 2005"
%End Program
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Delos
![](http://www.members.shaw.ca/rfolz/delos_avatar.gif)
|
Posted: Sun Apr 17, 2005 9:51 am Post subject: (No subject) |
|
|
This is interesting...you realize that by importing GUI, you're slowing your start up significantly. You only ever use GUI. commands once, and that's to set the GUI background colour...
You seeing the problem here?
Error trapping: you *really* need to work on this. All of the old favourites work. Input string where integers are asked for, excessive string length, Ctrl+Z...time to start trapping...
Now that you've pretty much got the hang of linear programming, it's time you moved onto something a little more object-oriented. No classes or pointers for you just yet...just spend some time looking at the Tutorials on Procedures, Functions, and Modules. |
|
|
|
|
![](images/spacer.gif) |
evogre3n
|
Posted: Sun Apr 17, 2005 1:29 pm Post subject: (No subject) |
|
|
Im looking into everything you have mentioned
The thing is, i asked my teacher, she says she doesnt want me using any of that, no procedures or anything, im not even allowed to use the "loop" command.. :S
THanks for the comments
Btw. does anyone know what this error could mean?
this line
code: | answer := givenVariable / (3 * (10 ** 8) ** 2) |
this error:
code: | Overflow in "**" operation. |
|
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sun Apr 17, 2005 1:56 pm Post subject: (No subject) |
|
|
It means your numbers are too big. Use real numbers.
Also, you got the equations wrong. First, the speed of light is 3e5, and we want to square that. So that's (3 x 10^5)^2. That is not the same as 3*10^8. Rather, it's the same as 9 x 10^10. So let's just use that number instead of doing these calculations over and over.
The second thing is that, I think, you've mixed up the equations. You've got m = ec^2. It should be this:
e = mc^2
m = e/c^2
So the code looks like this:
code: |
%Processing
if variableType = "m" or variableType = "M" then
answer := givenVariable * 90000000000.0
else
answer := givenVariable / 90000000000.0
end if
|
|
|
|
|
|
![](images/spacer.gif) |
Andy
|
Posted: Sun Apr 17, 2005 4:16 pm Post subject: (No subject) |
|
|
this program isnt all that useful... if you however added calculations for wavelengths of matters, or momentum of photons wit electron problems, then it would be better. also, mass starts off with negative energy, because the strong nulcear force binds the matter together and a certain amount of energy has to be provided inorder to liberate the nucleons |
|
|
|
|
![](images/spacer.gif) |
Delos
![](http://www.members.shaw.ca/rfolz/delos_avatar.gif)
|
Posted: Sun Apr 17, 2005 5:33 pm Post subject: (No subject) |
|
|
Hehe, quite true Andy...[memories of grade 12 physics rush back in]...
Ouch. That hurt. |
|
|
|
|
![](images/spacer.gif) |
evogre3n
|
Posted: Tue Apr 19, 2005 8:37 am Post subject: (No subject) |
|
|
if your ramblin on about the usefullness of the program, you obviously missed the point.
The point of this was to have me learn about if structures etc. not to make use of the fomula |
|
|
|
|
![](images/spacer.gif) |
jamonathin
![](http://compsci.ca/v3/uploads/user_avatars/57683465145f851a43dd9a.gif)
|
Posted: Tue Apr 19, 2005 11:30 am Post subject: (No subject) |
|
|
So you made this program so you could learn about if's, and your program's not that useful, so why did you submit it then, if you didn't want people to criticize it? To show off that you know how to use 'if' statements? ![Confused Confused](http://compsci.ca/v3/images/smiles/icon_confused.gif) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Catalyst
![](http://catalyze.mine.nu/jack_of_spades+100.jpg)
|
Posted: Tue Apr 19, 2005 9:46 pm Post subject: (No subject) |
|
|
the speed of light is 3e5 km/s but in this eq you should use 3e8 m/s |
|
|
|
|
![](images/spacer.gif) |
hacker101
|
Posted: Fri May 06, 2005 8:57 pm Post subject: (No subject) |
|
|
Nick:
Ms. **** would be proud. Nice program.
Mine was i=q/t |
|
|
|
|
![](images/spacer.gif) |
Andy
|
Posted: Sun May 08, 2005 4:43 pm Post subject: (No subject) |
|
|
ever heard of pm? |
|
|
|
|
![](images/spacer.gif) |
|
|