Anonymous user
Chemical calculator: Difference between revisions
m
→{{header|REXX}}: added the ability to have a common name for the chemical formula, presented the output better, reduced output clutter.
m (added whitespace, uncapitalized element names.) |
m (→{{header|REXX}}: added the ability to have a common name for the chemical formula, presented the output better, reduced output clutter.) |
||
Line 2,693:
This REXX version has some basic error checking to catch malformed chemical formulas.
Some extra coding was added to format the output better and to also include a common name for the chemical formula.
Also a more precise atomic mass for the (all) known elements is used (for instance, '''F''').▼
▲Also a more precise atomic mass for the (all) known elements is used;
Some of the elements added for the REXX example are:▼
▲Some of the (newer) elements added for the REXX example are:
seaborgium (Sg), bohrium (Bh), hassium (Hs), meitnerium (Mt), darmstadtium (Ds),▼
▲ seaborgium (Sg), bohrium (Bh), hassium (Hs), meitnerium (Mt), darmstadtium (Ds),
livermorium (Lv), tennessine (Ts), and oganesson (Og)▼
roentgenium (Rg), copernicium (Cn), nihoniym (Nh), flerovium (Fl), moscovium (Mc),
<lang rexx>/*REXX program calculates the molar mass from a specified chemical formula. */
numeric digits 30 /*ensure enough decimal digits for mass*/
Line 2,729 ⟶ 2,731:
@.Cn=285 ; @.Hs=277 ; @.No=259 ; @.Sc= 44.955912; @.Zr= 91.224
@.Ubn=299 ; @.Uue=315
say center(' chemical formula {common name} ', 45) center("molar mass", 16)
if $='' | $="," then $= ' H H2 H2O H2O2 (HO)2 Na2SO4 C6H12 ' ,▼
say center(''
▲if $='' | $="," then $= '
'(HO)2{hydrogen_peroxide} H2O{water} Na2SO4{sodium_sulfate}',
'C6H12{cyclohexane} COOH(C(CH3)2)3CH3{butyric_acid}' ,
'C6H4O2(OH)4{vitamin_C} C27H46O{cholesterol} Uue{ununennium}',
'Mg3Si4O10(OH)2{talc}'
do j=1 for words($); x= word($, j) /*obtain the formula of the molecule. */
name= strip(x ' 'translate(name, 'ff'x,"_")) /* " " molar mass; fix─up name. */
if mm<0 then iterate /*if function had an error, skip output*/
say
end /*j*/
exit /*stick a fork in it, we're all done. */
Line 2,777 ⟶ 2,786:
{{out|output|text= when using the default inputs:}}
<pre>
chemical formula {common
───────────────────────────────────────────── ────────────────
▲ molar mass of H2 is 2.01588
H
H2 {molecular hydrogen}
H2O2 {hydrogen peroxide}
(HO)2 {hydrogen peroxide}
H2O
Na2SO4
C6H12
COOH(C(CH3)2)3CH3 {butyric acid} 186.29118
▲ molar mass of C27H46O is 386.65354
C6H4O2(OH)4 {vitamin C}
C27H46O {cholesterol} 386.65354
Uue {ununennium} 315
Mg3Si4O10(OH)2 {talc} 379.26568
</pre>
|