Do math

Thanks to coder 777 my code "works", it just doesn't do what I was hoping it would. I want it to calculate the weight of a compound (the reason for the first 20 elements as floating numbers) but I don't know how to do that yet, especially considering I have no idea how many variables are going to be used.
It needs to
Thank you in advance!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
    #include <fstream>

using namespace std;

int main()
{

float h = 1.0079;
float he = 4.002;
float li = 6.941;
float be = 9.012;
float b = 10.811;
float c = 12.0107;
float n = 14.0067;
float o = 15.9994;
float f = 18.998;
float ne = 20.1797;
float na = 22.989;
float mg = 24.3050;
float al = 26.981;
float si = 28.0855;
float p = 30.973;
float s = 32.065;
float cl = 35.453;
float ar = 39.948;
float k = 39.948;
float ca = 40.078;

char number[101];
    char cmpnd[101];
    cout << "Please input chemical formula with * between every symbol.\n all lower case please\n example: si o 2" << endl;
    cin.getline (cmpnd, 101);
   ofstream a_file ( "calculator.txt" );
    a_file<<cmpnd;
    a_file.close();
     ifstream b_file ( "calculator.txt" );
    b_file>>cmpnd;
    number[101] = cmpnd[101];
    cout<<number;
}
Last edited on
you need to #include <fstream>

EDIT: This number[101] = cmpnd[101]; is invalid (out of bounds)
Last edited on
Oh yeah
thanks.
Topic archived. No new replies allowed.