Hello,
I'm to read in a file with element symbols and atomic weights and store it in a linked list to compare to a formula to determine molecular weight, but am having trouble extracting the data correctly.
We are learning in class about c strings and that is what I need to use in conjunction with a linked list.
specifically, my problem is just trying to read in the data correctly.
here is what the data looks like:
Mg 24.305
H 1.0080
F 18.9984
Au 196.9665
I 126.9045
Fe 55.847
Th 232.0381
I figured that I could read in the name of the elements as characters store them in eName, and then read in the weight as double and store that value into eWght. This would prevent having to convert the char numbers to actual digits(or so I thought).
any help is appreciated, Thank you.
If I just inFile the data, would I be able to compare it to another input file.
For example I need to compare oxygen and hydrogen to a line of text like this
Ex. H(2)0
Would I need my data to be stored as a c string so I can count each instance I find H and O?
So basically, the number in the parentheses would tell me how many elements are in the formula.
And then the program would figure out molecular weight.
If I just inFile the data, would I be able to compare it to another input file.
Not if all you do is display it on the console as I did.
But you can use that loop structure as a basis. It is a good starting point. Where I have the cout, you would need to add the node to the list and so on.
Thank you! I was forgetting about that last entry inFile.getline (elements->eName, 3, ‘ ’ )
the single quotes.
Will I still be able to use elements->eWght to store a double or would I also need to read the decimal number character by character?