Advertisement
Guest User

Untitled

a guest
Jul 9th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h> // dla kolorow
  3. #include <conio.h> // dla getch()
  4. #include <time.h> // dla gry losowej
  5. using namespace std;
  6. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  7. void kalkulator()
  8. {
  9. SetConsoleTextAttribute(hConsole, 15); // kolor bialy
  10. while(true)
  11. {
  12. system("cls");
  13. float x,y, w;
  14. cout << " 1. Dodawanie \n 2. Odejmowanie \n 3. Mnozenie \n 4. Dzielenie \n 5. Opusc program \n" << endl;
  15. char menu_kalk = getch();
  16. switch(menu_kalk)
  17. {
  18. case '1':
  19. {
  20. cout << "Podaj liczby ktore chcesz do siebie dodac: \n";
  21. cout << "1: ";
  22. cin >> x;
  23. cout << "2: ";
  24. cin >> y;
  25. w = x+y;
  26. cout << "Suma to: " << w;
  27. Sleep(3500);
  28. break;
  29. }
  30. case '2':
  31. {
  32. cout << "Podaj liczby ktore chcesz od siebie odjac: \n";
  33. cout << "1: ";
  34. cin >> x;
  35. cout << "2: ";
  36. cin >> y;
  37. w = x-y;
  38. cout << "Roznica to: " << w;
  39. Sleep(3500);
  40. break;
  41. }
  42. case '3':
  43. {
  44. cout << "Podaj liczby ktore chcesz pomnozyc: \n";
  45. cout << "1: ";
  46. cin >> x;
  47. cout << "2: ";
  48. cin >> y;
  49. w = x*y;
  50. cout << "Iloczyn to: " << w;
  51. Sleep(3500);
  52. break;
  53. }
  54. case '4':
  55. {
  56. powrot:
  57. cout << "Podaj liczby ktore chcesz podzielic \n";
  58. cout << "1: ";
  59. cin >> x;
  60. cout << "2: ";
  61. cin >> y;
  62. if(y == 0)
  63. {
  64. cout << "Nie mozna dzielic przez zero." << endl;
  65. goto powrot;
  66. }
  67. w = x/y;
  68. cout << "Iloraz to: " << w;
  69. Sleep(3500);
  70. break;
  71. }
  72. case '5':
  73. {
  74. exit(0);
  75. break;
  76. }
  77. default:
  78. {
  79. kalkulator();
  80. }
  81. }
  82. }
  83. }
  84.  
  85. void gra()
  86. {
  87. system("cls");
  88. srand(time(NULL));
  89. SetConsoleTextAttribute(hConsole, 14); // kolor zolty
  90. cout << " WITAJ W GRZE LOSOWEJ!" << endl << endl;
  91. SetConsoleTextAttribute(hConsole, 15); // kolor bialy
  92. cout << "Twoje zadanie to zgadniecie jednej liczby od 1 do 10! Powodzenia :-)" << endl;
  93.  
  94. int strzal, liczba = rand()%10+1, i;
  95. string gram;
  96. while(strzal != liczba)
  97. {
  98. i++;
  99. SetConsoleTextAttribute(hConsole, 15); // kolor bialy
  100. cout << "Strzal nr: " << i << ": ";
  101. cin >> strzal;
  102. if(strzal == liczba)
  103. {
  104. SetConsoleTextAttribute(hConsole, 10); // kolor zielony
  105. cout << "Gratulacje! Udalo Ci sie wygrac. Jezeli chcesz zagrac jeszcze raz napisz 'gram'" << endl;
  106. cout << "A moze chcesz cos policzyc? Napisz wtedy 'kalkulator': ";
  107. cin >> gram;
  108. if(gram == "gram") gra();
  109. else if(gram == "kalkulator") kalkulator();
  110. else exit(0);
  111. }
  112. else if(strzal > liczba)
  113. {
  114. SetConsoleTextAttribute(hConsole, 12); // kolor czerwony
  115. cout << "Za duzo :-(" << endl;
  116. }
  117. else if(strzal < liczba)
  118. {
  119. SetConsoleTextAttribute(hConsole, 12); // kolor czerwony
  120. cout << "Za malo :-(" << endl;
  121. }
  122. }
  123.  
  124.  
  125. }
  126.  
  127. void dalej()
  128. {
  129. system("cls");
  130. SetConsoleTextAttribute(hConsole, 14); // kolor zolty
  131. cout << " ~MENU~" << endl;
  132. cout << "Wybierz co chcesz robic dalej :-)" << endl;
  133.  
  134. SetConsoleTextAttribute(hConsole, 15); // kolor bialy
  135. cout << "1. Kalkulator" << endl;
  136. cout << "2. Gra losowa" << endl;
  137. char wybierz = getch();
  138. switch(wybierz)
  139. {
  140. case '1':
  141. {
  142. kalkulator();
  143. break;
  144. }
  145. case '2':
  146. {
  147. gra();
  148. break;
  149. }
  150. }
  151.  
  152. }
  153.  
  154. int main()
  155. {
  156. SetConsoleTextAttribute(hConsole, 14); // kolor zolty
  157.  
  158. cout << " WITAJ W PROGRAMIE!" << endl;
  159.  
  160. SetConsoleTextAttribute(hConsole, 15); // kolor bialy
  161.  
  162. cout << "Zaloguj sie do programu, aby przejsc dalej." << endl << endl;
  163.  
  164. SetConsoleTextAttribute(hConsole, 10); // kolor zielony
  165.  
  166. cout << "a) Logowanie" << endl;
  167. cout << "b) Podpowiedz" << endl;
  168.  
  169. char menu = getch();
  170. string login, haslo;
  171. system("cls");
  172. switch(menu)
  173. {
  174. case 'a':
  175. {
  176. podpowiedz:
  177. cout << "Login: ";
  178. cin >> login;
  179. cout << "Haslo: ";
  180. cin >> haslo;
  181. if(login == "admin" && haslo == "admin")
  182. {
  183. cout << endl <<"Udalo Ci sie zalogowac!" << endl;
  184. dalej();
  185. }
  186. else goto b;
  187. break;
  188. }
  189.  
  190. case 'b':
  191. {
  192. b:
  193. cout << endl << "admin/admin";
  194. Sleep(2000);
  195. system("cls");
  196. goto podpowiedz;
  197. break;
  198. }
  199. default:
  200. {
  201. cout << "Zla opcja!" << endl;
  202. cout << "Przekierowywanie do logowania..." << endl;
  203. cout << "3...";
  204. Sleep(1000);
  205. cout << "2...";
  206. Sleep(1000);
  207. cout << "1...";
  208. Sleep(1000);
  209. system("cls");
  210. goto podpowiedz;
  211. break;
  212. }
  213. }
  214.  
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement