Advertisement
kubbur

Untitled

Mar 8th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 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.  
  17.  
  18. int main()
  19. {
  20. srand(time(NULL));
  21. system("chcp 1252>nul"); // isl stafir
  22.  
  23. cout << "Fýlukallinn" << endl; // titill á leik
  24. // PlaySound(TEXT("game.wav"), NULL, SND_SYNC); /* lærði af youtube þurfti að bæta við input i propertys
  25. // spilar hljóð*/
  26. string valk;//upphafsval
  27.  
  28. cout << "SHALL WE PLAY A GAME?" << endl; // texti ef ekkert audio
  29. cout << "Veldu Y/N (Yes/No)" << endl; //valkostir
  30. cout << ">>";
  31. cin >> valk;
  32.  
  33. if (valk =="y")
  34. {
  35.  
  36.  
  37.  
  38. ifstream txt("ordaskra.txt");
  39. string myArray[50];
  40. if (txt.is_open())
  41. {
  42. for (int i = 1; i < 20; ++i) // les úr orðaskrá inn í array
  43. {
  44. txt >> myArray[i];
  45. }
  46. }
  47. for (int j = 1; j < 20; j++) // velur random stað í array og prentar út
  48. {
  49.  
  50. j = rand() % 19 + 1;
  51. string f = myArray[j];
  52.  
  53. int count = 0;
  54. char checkstafur;
  55. cout << f << endl;
  56. cout << "Það eru " << f.size() << " stafir í orðinu" << "\n";
  57. cout << "giskaðu á staf";
  58. cin >> checkstafur;
  59. cout << "það eru " << count << "af" << checkstafur << "í orðinu\n";
  60. for (int i = 0; i < f.size(); i++)
  61. {
  62.  
  63. if (f[i] == checkstafur)
  64. {
  65. ++count;
  66. }
  67.  
  68. }
  69. system("pause");
  70. }
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement