#include #include #include using namespace std; int main() // this function has grown far too big { ifstream inf; inf.open("/home/www/class/een118/a3010b.txt"); if (inf.fail()) { cerr << "Can't open file\n"; exit(1); } string syms[120], names[120]; double atwts[120]; string sym, name; double atwt; int atno = 0; while (true) { inf >> sym >> name >> atwt; if (inf.fail()) break; atno += 1; syms[atno] = sym; names[atno] = name; atwts[atno] = atwt; } const int entries = atno; inf.close(); for (atno = 1; atno <= entries; atno += 1) cout << atno << ", '" << syms[atno] << "', '" << names[atno] << "', " << atwts[atno] << "\n"; double molwt = 0; int num; while (true) { cout << "> "; cin >> sym; if (cin.fail()) break; for (atno = 1; atno <= entries; atno += 1) if (syms[atno] == sym) break; if (atno <= entries) { cout << "number? "; cin >> num; cout << atno << ", '" << syms[atno] << "', '" << names[atno] << "', " << atwts[atno] << "\n"; molwt += atwts[atno] * num; } else cout << "'" << sym << "' not found\n"; } cout << "Molecular weight " << molwt << "\n"; }