Computer Science Canada

chemistry prog

Author:  bugzpodder [ Fri Dec 29, 2006 1:05 pm ]
Post subject:  chemistry prog

chemisty program i wrote in grade 12 to memorize charges...

code:

#include<vector>
#include<fstream>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    vector<pair<string,string> > v;
    int i,N,cnt;
    string str;
    vector<bool> corr;
    ifstream fin("chem.txt");
    pair<string,string> p;
    while (fin>>p.first>>p.second){
          v.push_back(p);
          corr.push_back(false);
    }
    N = v.size();
    random_shuffle(v.begin(),v.end());
    cnt=0;

    while(cnt<N){
       for (i=0;i<N;i++)
           if (!corr[i]){
              cout<<v[i].first<<" ";
              cin>>str;
              if (str==v[i].second) {
                 cout<<"Correct!  "<<++cnt<<endl;
                 corr[i]=true;
              }
              else cout<<"Correct answer is: "<<v[i].second<<endl;
           }
    }

    return 0;
}


: