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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#include <iostream>
#include <string>
using namespace std;
// some global variables required //
const string eDICT[119] =
{"\0", "Hydrogen", "Helium" , "Lithium" , "Berylium" , "Boron" , "Carbon" , "Nitrogen" , "Oxygen"
, "Fluorine" , "Neon" , "Sodium" , "Magnesium" , "Aluminum" , "Silicon" , "Phosphorous"
, "Sulfur" , "Chlorine" , "Argon" , "Potassium" , "Calcium" , "Scandium" , "Titanium"
, "Vanadium" , "Chromium" , "Manganese" , "Iron" , "Cobalt" , "Nickel" , "Copper"
, "Zinc" , "Gallium" , "Germanium" , "Arsenic" , "Selenium" , "Bromine" , "Krypton"
, "Rubidium" ,"Strontium" , "Yttrium" , "Zirconium" , "Niobium" , "Molybdenum" , "Technetium"
, "Ruthenium" , "Rhodium" , "Palladium" , "Silver" , "Cadmium" , "Indium" , "Tin" , "Antimony"
, "Tellurium" , "Iodine" , "Xenon" , "Cesium" , "Barium" , "Lanthanum" , "Cerium" , "Praseodymium"
, "Neodymium" , "Promethium" , "Samarium" , "Europium" , "Gadolinium" , "Terbium" , "Dysprosium"
, "Holmium" , "Erbium" , "Thulium" , "Ytterbium" , "Lutetium" , "Hafnium" , "Tantalum" , "Tungsten"
, "Rhenium" , "Osmium" , "Iridium" , "Platinum" , "Gold" , "Mercury" , "Thalium" , "Lead"
, "Bismuth" , "Polonium" , "Astatine" , "Radon" , "Francium" , "Radium" , "Actinium" , "Thorium"
, "Protactnium" , "Uranium" , "Neptunium" , "Plutonium" , "Americium" , "Curium" , "Berkelium" , "Californium"
, "Einsteinium" , "Fermium" , "Mendelevium" , "Nobelium" , "Lawrencium" , "Rutherfordium" , "Dubnium"
, "Seaborgium" , "Bohrium" , "Hassium" , "Meitnerium" , "Darmstadtium" , "Roentgenium" , "Copernicium"
, "Ununtrium" , "Flerovium" , "Ununpentium" , "Livermorium" , "Ununseptium" , "Ununoctium"
} ;
int main()
{
string element1, cap_input;
getline(cin,element1);
string cap_notation(string element1);
cap_input = cap_notation(element1);
string first_reactant(string cap_input); // compares user input to the values inside of eDICT [1 ~ 119]
cout << first_reactant (cap_input); /* doesn't print this out; crashes */
return 0;
}
string cap_notation (string element1)
{
char temp;
temp = toupper(element1[0]);
element1[0] = temp;
for (int i=1; element1[i] != '\0'; i++)
{
temp = tolower(element1[i]);
element1[i] = temp;
}
return element1;
}
string first_reactant (string cap_input)
{
string error = "I'm sorry, you didn't enter a valid element\n";
for (int x = 1; x == 119; x++)
{
if (cap_input.compare(eDICT[x]) == 0) // this crashes the program
return eDICT[x];
else
return error;
}
}
|