Program to Calculate Molar Mass

This is a discussion on Program to Calculate Molar Mass within the C Programming forums, part of the General Programming Boards category; I need to write a C program to calculate the molar mass when given a chemical formula. For example: C6H13NO2. ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    2

    Program to Calculate Molar Mass

    I need to write a C program to calculate the molar mass when given a chemical formula. For example: C6H13NO2.

    I've gotten my code to get the formula into a string and validate it. I've stored the possible atomic masses (C,H,N,O,S) in an array. And I'm using a for loop to process the values in the formula string.

    What I can't figure out is how to put the digits in the formula together as an integer value and multiply that value by the atomic mass represented by the preceding letter.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Have you looked into strtol?

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    2
    Quote Originally Posted by tabstop View Post
    Have you looked into strtol?
    Yes, I am working with that, but it's giving me errors when I run the program. I'll keep working on it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. program to calculate the square root
    By saszew in forum C Programming
    Replies: 7
    Last Post: 10-28-2008, 01:53 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  3. Need help with small program to calculate a salary
    By Guti14 in forum C++ Programming
    Replies: 13
    Last Post: 01-11-2004, 05:54 PM
  4. Replies: 2
    Last Post: 05-10-2002, 05:16 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21