Advertisement
kubbur

Untitled

Mar 9th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdlib.h>
  3. #include <windows.h>
  4. #include <iostream>
  5. #include <fstream>
  6. #include <vector>
  7. #include <string>
  8. #include <cstdlib>
  9. #include <cmath>
  10. #include <conio.h>
  11. #include <time.h>
  12. #include <sstream>
  13. #include <MMSystem.h> // Fyrir multi media stuðning
  14. using namespace std;
  15.  
  16. class mya {
  17. private:
  18. string myArray[50];
  19.  
  20. int j;
  21.  
  22. public:
  23. string f;
  24. void arrayfiller()
  25. {
  26. ifstream txt("ordaskra.txt");
  27.  
  28. if (txt.is_open())
  29. {
  30. for (int i = 1; i < 20; ++i) // les úr orðaskrá inn í array
  31. {
  32. txt >> myArray[i];
  33.  
  34. }
  35. }
  36. }
  37.  
  38. void arrayrander()
  39. {
  40. j = rand() % 19 + 1;
  41. string f = myArray[j];
  42. }
  43.  
  44. };
  45. int main()
  46. {
  47. mya arrayfiller;
  48. string valk;//upphafsval
  49. srand(time(NULL));
  50. system("chcp 1252>nul"); // isl stafir
  51. cout << "Fýlukallinn" << endl; // titill á leik
  52.  
  53. cout << "SHALL WE PLAY A GAME?" << endl; // texti ef ekkert audio
  54. cout << "Veldu Y/N (Yes/No)" << endl; //valkostir
  55. cout << ">>";
  56. cin >> valk;
  57.  
  58. if (valk == "y")
  59. {
  60.  
  61. cout << f << endl;
  62.  
  63. int count = 0;
  64. char checkstafur;
  65.  
  66. cout << "Það eru " << f.size() << " stafir í orðinu" << "\n";
  67.  
  68. cout << "giskaðu á staf\n";
  69. cin >> checkstafur;
  70. cout << "það eru " << count << "af stafnum " << checkstafur << "í orðinu\n";
  71. for (int i = 0; i < f.size(); i++)
  72. {
  73.  
  74. if (f[i] == checkstafur)
  75. {
  76. ++count;
  77. }
  78.  
  79. }
  80.  
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement