Advertisement
kubbur

Untitled

Mar 9th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 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. int j;
  20.  
  21. public:
  22. string f;
  23.  
  24. void arrayfiller()
  25. {
  26. ifstream txt("ordaskra.txt"); //opnar inn í orðaskrá
  27. if (txt.is_open())
  28. {
  29. for (int i = 1; i < 20; ++i) // les úr orðaskrá inn í array
  30. {
  31. txt >> myArray[i];
  32.  
  33. }
  34. }
  35. }
  36.  
  37. void arrayrander() //velur random
  38. {
  39. j = rand() % 19 + 1;
  40. string f = myArray[j];
  41.  
  42. }
  43.  
  44. };
  45. int main()
  46.  
  47. {
  48. mya b1;
  49.  
  50.  
  51. string valk;//upphafsval
  52. srand(time(NULL));
  53. system("chcp 1252>nul"); // isl stafir
  54. cout << "Fýlukallinn" << endl; // titill á leik
  55.  
  56. cout << "SHALL WE PLAY A GAME?" << endl; // texti ef ekkert audio
  57. cout << "Veldu Y/N (Yes/No)" << endl; //valkostir
  58. cout << ">>";
  59. cin >> valk;
  60.  
  61. if (valk == "y")
  62. {
  63.  
  64. b1.arrayfiller();
  65. // string f = b1.f;
  66. b1.arrayrander();
  67.  
  68. int count = 0;
  69. char checkstafur;
  70.  
  71. cout << "Það eru " << f.size() << " stafir í orðinu" << "\n";
  72.  
  73.  
  74. cout << "giskaðu á staf\n";
  75. cin >> checkstafur;
  76. cout << "það eru " << count << "af stafnum " << checkstafur << "í orðinu\n";
  77. for (int i = 0; i < f.size(); i++)
  78. {
  79.  
  80. if (f[i] == checkstafur)
  81. {
  82. ++count;
  83. }
  84.  
  85. }
  86.  
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement