프로그래밍언어/C & CPP

문자열 클래스, 파일 클래스 실습 - 영어단어 맞추기 게임

Isaac87 2015. 2. 13. 12:20

 

 

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main()
{
 ifstream f;
 string eng, kor, answer;
 int o = 0, x = 0;

 f.open("answer.txt");

 while(!f.eof())
 {
  f >> eng >> kor;
  cout << eng << endl;
  cout << "답 입력 : ";
  cin >> answer;
  if(kor == answer)
  {
   cout << "맞았습니다." << endl;
   o++;
  }
  else
  {
   cout << "틀렸습니다." << endl;
   x++;
  }
 }
 cout << "정답개수 : " << o << ", 오답개수 : " << x << endl;

 f.close();


 return 0;
}
 

 

answer.txt