-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
45 lines (41 loc) · 902 Bytes
/
main.cpp
File metadata and controls
45 lines (41 loc) · 902 Bytes
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
#include"Jonfor.hpp"
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
int main()
{
srand(time(NULL));
vector<Jonfor> jonfor;
ifstream file;
file.open("joner.txt");
do {
string temp, temp_jon, temp_namn;
size_t pos;
getline(file, temp);
pos = temp.find(',');
temp_jon = temp.substr(0, pos);
temp_namn = temp.substr(pos+1, temp.size());
Jonfor temp_jonfor;
temp_jonfor.namn = temp_namn;
temp_jonfor.formel = temp_jon;
jonfor.push_back(temp_jonfor);
} while(!file.eof());
file.close();
bool running = true;
int r_jon;
while(running)
{
string guess;
r_jon = rand()%jonfor.size();
cout<<"Question: "<<jonfor[r_jon].namn<<endl;
getline(cin, guess);
if(guess == jonfor[r_jon].formel) {
cout<<"Right!"<<endl;
} else {
cout<<"Wrong! Right answer is: '"<<jonfor[r_jon].formel<<"'"<<endl;
}
guess.clear();
cin.clear();
}
}