Compute the number of molecules I would like my program to be reviewed. I had to write a simple program that calculates the number of molecules in a hydrocarbon. 


1 carbon atom has 12 AMU.
1 hydrogen atom has 1 AMU.




#include &lt;iostream&gt;
using namespace std;



int main()
{
    cout &lt;&lt; "Enter mass of hydrocarbon (in grams)\n"
            "followed by the number of carbon atoms\n"
            "followed by the number of hydrogen atoms\n"
            "(e.g. 10.5 2 6): " &lt;&lt; flush;

    float mass;
    float carbonAtoms;
    int hydrogenAtoms;
    cin &gt;&gt; mass &gt;&gt; carbonAtoms &gt;&gt; hydrogenAtoms;

    long formulaWght = (carbonAtoms * 12) + (hydrogenAtoms * 1);


    double molecules = (mass / formulaWght) * 6.02e23;



    cout &lt;&lt; mass &lt;&lt; " grams of hydrocarbon\nwith "
            &lt;&lt; carbonAtoms &lt;&lt; " carbon atom(s) and "
               &lt;&lt; hydrogenAtoms &lt;&lt; " hydrogen atom(s)\ncontains "
                  &lt;&lt; molecules &lt;&lt; " molecules" &lt;&lt; endl;

    return 0;
}
Do not use using namespace std. Read
this
Instead of using "magic numbers" in your program. Use symbolic
constants. CARBON_AMU and HYDROGEN_AMU should be ints. 

const int CARBON_AMU= 12;
const int HYDROGEN_AMU = 1;
const double AVOGADRO = 6.02214141070409084099072e23;

Utilize functions in your program, instead of initializing a
variable with an expression:

long formulaWeight(int carbonAtoms, int hydrogenAtoms){
    return((carbonAtoms * CARBON_AMU) + (hydrogenAtoms * HYDROGEN_AMU));
}

double numMolecules(float mass, long formulaWeight)
{
    return((mass / formulaWeight) * AVOGADRO);
}

(e.g. 10.5 2 6): " &lt;&lt; flush;

I don't see any advantage in using std::flush. You can remove it.
Fix your indentation. This is much easier to read:

cout &lt;&lt; mass &lt;&lt; " grams of hydrocarbon\nwith "
     &lt;&lt; carbonAtoms &lt;&lt; " carbon atom(s) and "
     &lt;&lt; hydrogenAtoms &lt;&lt; " hydrogen atom(s)\ncontains "
     &lt;&lt; molecules &lt;&lt; " molecules" &lt;&lt; endl;