#include #include #include using namespace std; int main() { double molwt = 0.0; cout << "Enter control-d when done\n"; ifstream elf; while (true) { elf.open("new.txt"); if (elf.fail()) { cout << "Can't open the file\n"; exit(1); } cout << "Enter an element's symbol: "; string wanted; cin >> wanted; if (cin.fail()) break; bool found = false; while (true) { string symbol, name; int atno; double atwt; elf >> symbol >> name >> atno >> atwt; if (elf.fail()) break; if (symbol == wanted) { cout << "Symbol: " << symbol << "\n"; cout << "Name " << name << "\n"; cout << "atomic number: " << atno << "\n"; cout << "atomic weight: " << atwt<< "\n"; molwt += atwt; found = true; } } if (found == false) { cout << "Symbol " << wanted << " was not found\n"; exit(1); } elf.close(); } cout << "\nTotal molecular weight = " << molwt << "\n"; }