I made a quiz-game.It is able to write the name(you have already chosen)and the score in a file named "Quiz-Score". But when i run the program again and write another name it erases the previous one.
#include<iostream>
#include<string>
#include<windows.h>
#include<fstream>
usingnamespace std;
int main()
{
ofstream fout ("Quiz-Score");
int score=0;
string ans1,ans2,ans3,ans4,ans5;
string name;
string check;
cout<<"Welcome to the Quiz!"<<endl;
cout<<"The rules:"<<endl<<"You win one point for each right answer"<<endl;
cout<<"For a wrong answer you lose tha game(GAME OVER)!"<<endl;
cout<<"There are 5 questions"<<endl;
cout<<"Write the letter of the choice example:"<<endl;
cout<<"When did the second world war start?:";
cout<<"a.1943 b.1945 c.1939 d.1934"<<endl;
Sleep(100);
cout<<"c."<<endl;
cout<<"Correct!"<<endl;
cout<<endl;
cout<<"Who was the first emperor of the Byzantine empire?"<<endl<<"a.Valens b.Gratian c.Theodosius d.Constantine The Great"<<endl;
cin>>ans1;
if(ans1=="d")
{
score++;
cout<<"Correct!"<<endl;
cout<<"Who was the designer of ENIAC, the first digital computer?"<<endl;
cout<<"a.John Maucley b.Bill Gates c.Steve Jobs d.Bob Miner"<<endl;
cin>>ans2;
if(ans2=="a")
{
score++;
cout<<"Correct!"<<endl;
cout<<"What country has borders with Uzbekistan?"<<endl;
cout<<"a.Turkey b.Egypt c.Turkmenistan d.Iran?"<<endl;
cin>>ans3;
if(ans3=="c")
{
score++;
cout<<"Correct!"<<endl;
cout<<"When did the first world war begin?"<<endl;
cout<<"a.1914 b.1915 c.1913 d.1916"<<endl;
cin>>ans4;
if(ans4=="a")
{
score++;
cout<<"Correct!"<<endl;
cout<<"What metal's symbol is FE?"<<endl;
cout<<"a.Gold b.Iron c.Bronze d.Copper"<<endl;
cin>>ans5;
if(ans5=="b")
{
score++;
cout<<"Correct!"<<endl;
cout<<"Please write your name:";
cin>>name;
cout<<endl;
cout<<"Your score is in the file Quiz-Score"<<endl;
fout<<name<<"-"<<score;
}
}
else
{
cout<<"Wrong"<<endl;
cout<<"Please enter your name:";
cin>>name;
fout<<name<<"-"<<score;
cout<<endl;
cout<<"Your score is in the file Quiz-Score"<<endl;
Sleep(1000);
return 0;
}
}
else
{
cout<<"Wrong"<<endl;
cout<<"Please enter your name:";
cin>>name;
fout<<name<<"-"<<score;
cout<<endl;
cout<<"Your score is in the file Quiz-Score"<<endl;
Sleep(1000);
return 0;
}
}
else
{
cout<<"Wrong"<<endl;
cout<<"Please enter your name:";
cin>>name;
fout<<name<<"-"<<score;
cout<<endl;
cout<<"Your score is in the file Quiz-Score"<<endl;
Sleep(1000);
return 0;
}
}
else
{
cout<<"Wrong"<<endl;
cout<<"Please enter your name:";
cin>>name;
fout<<name<<"-"<<score;
cout<<endl;
cout<<"Your score is in the file Quiz-Score"<<endl;
Sleep(1000);
return 0;
}
}