Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <stdlib.h>
- #include <windows.h>
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <cstdlib>
- #include <cmath>
- #include <conio.h>
- #include <time.h>
- #include <sstream>
- #include <MMSystem.h> // Fyrir multi media stuðning
- using namespace std;
- class mya {
- private:
- string myArray[50];
- int j;
- public:
- string f;
- void arrayfiller()
- {
- ifstream txt("ordaskra.txt");
- if (txt.is_open())
- {
- for (int i = 1; i < 20; ++i) // les úr orðaskrá inn í array
- {
- txt >> myArray[i];
- }
- }
- }
- void arrayrander()
- {
- j = rand() % 19 + 1;
- string f = myArray[j];
- }
- };
- int main()
- {
- mya b1;
- string valk;//upphafsval
- srand(time(NULL));
- system("chcp 1252>nul"); // isl stafir
- cout << "Fýlukallinn" << endl; // titill á leik
- cout << "SHALL WE PLAY A GAME?" << endl; // texti ef ekkert audio
- cout << "Veldu Y/N (Yes/No)" << endl; //valkostir
- cout << ">>";
- cin >> valk;
- if (valk == "y")
- {
- b1.arrayrander();
- b1.arrayfiller();
- // string f = b1.f;
- int count = 0;
- char checkstafur;
- cout << "Það eru " << f.size() << " stafir í orðinu" << "\n";
- cout << "giskaðu á staf\n";
- cin >> checkstafur;
- cout << "það eru " << count << "af stafnum " << checkstafur << "í orðinu\n";
- for (int i = 0; i < f.size(); i++)
- {
- if (f[i] == checkstafur)
- {
- ++count;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement