Hi Im makin a program in c++ for chemistry conversions, but I'm having trouble with the scientific notation of a constant heres the code
#include <iostream> // This program is for basic conversions in chemistry
#include <string>
using namespace std;
int main()
{
float moles;
float atoms;
float grams;
int choice; double const avo = 6.022e+23;
cout<<"What would you like to convert ";
cout<<"Press 1 for moles to atoms ";
cout<<"Press 2 for atoms to moles ";
cout<<"Press 3 for grams to atoms ";
cout<<"Press 4 for atoms to grams ";
cout<<"Press 5 for moles to grams ";
cout<<"Press 6 for grams to moles ";
cin>> choice;
if ( choice == 1 ) {
cout.precision(4);
cout<<"Enter a number of moles ";
atoms = moles * avo;
cin>> moles;
cout<<"The number of atoms are "<< atoms << "\n";
cin.ignore();
}
cin.get();
return 0;
}
The code I think I'm having trouble with is the stuff in bold could some one please comment. This is not for school either my school, sadly, doesn't have a programming class which sucks, but any how please help. Thanks in advanced whOOper
Thanks for the post, but if you look in the above code I posted with the question I did this and Im getting answers that are way off. could it possibly just be a computer error although I doubt that.
Hello there,
I don't know if you're still checking up on this post but anyway I just wanted to make a little correction concerning the way you are calculating the number of atoms.
Your program is not scientificaly correct, I say this because the value you are obtaining with the operation moles * avo is the number of molecules, not atoms. In order to calculate the number of atoms you'd need to know what element we are talking about.
The oxygen molecule, O2, for example, is composed by two atoms of oxygen. 1 mol of oxygen doesn't have 6.02e+23 atoms, it has 6.02e+23 molecules and 12.04e+23 atoms, because in this case you multiply the Avogadro constant by two.
Another example, the methane molecule, CH4, it's 1 carbon atom and 4 Hydrogen linked together. 1 mol of methane has 6.02e+23 molecules, 6.02e+23 atoms of carbon and 4*6.02e+23 atoms of hydrogen, 26.10e+24 atoms in total (no calculator here, and i'm sleepy so I can't ensure my calculations' "rightness").
Hi thanks for that update I just found out about that problem yesterday Im going to my chem teacher to see if he has general equations I can use. Thanks for that