Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h> // dla kolorow
- #include <conio.h> // dla getch()
- #include <time.h> // dla gry losowej
- using namespace std;
- HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- void kalkulator()
- {
- SetConsoleTextAttribute(hConsole, 15); // kolor bialy
- while(true)
- {
- system("cls");
- float x,y, w;
- cout << " 1. Dodawanie \n 2. Odejmowanie \n 3. Mnozenie \n 4. Dzielenie \n 5. Opusc program \n" << endl;
- char menu_kalk = getch();
- switch(menu_kalk)
- {
- case '1':
- {
- cout << "Podaj liczby ktore chcesz do siebie dodac: \n";
- cout << "1: ";
- cin >> x;
- cout << "2: ";
- cin >> y;
- w = x+y;
- cout << "Suma to: " << w;
- Sleep(3500);
- break;
- }
- case '2':
- {
- cout << "Podaj liczby ktore chcesz od siebie odjac: \n";
- cout << "1: ";
- cin >> x;
- cout << "2: ";
- cin >> y;
- w = x-y;
- cout << "Roznica to: " << w;
- Sleep(3500);
- break;
- }
- case '3':
- {
- cout << "Podaj liczby ktore chcesz pomnozyc: \n";
- cout << "1: ";
- cin >> x;
- cout << "2: ";
- cin >> y;
- w = x*y;
- cout << "Iloczyn to: " << w;
- Sleep(3500);
- break;
- }
- case '4':
- {
- powrot:
- cout << "Podaj liczby ktore chcesz podzielic \n";
- cout << "1: ";
- cin >> x;
- cout << "2: ";
- cin >> y;
- if(y == 0)
- {
- cout << "Nie mozna dzielic przez zero." << endl;
- goto powrot;
- }
- w = x/y;
- cout << "Iloraz to: " << w;
- Sleep(3500);
- break;
- }
- case '5':
- {
- exit(0);
- break;
- }
- default:
- {
- kalkulator();
- }
- }
- }
- }
- void gra()
- {
- system("cls");
- srand(time(NULL));
- SetConsoleTextAttribute(hConsole, 14); // kolor zolty
- cout << " WITAJ W GRZE LOSOWEJ!" << endl << endl;
- SetConsoleTextAttribute(hConsole, 15); // kolor bialy
- cout << "Twoje zadanie to zgadniecie jednej liczby od 1 do 10! Powodzenia :-)" << endl;
- int strzal, liczba = rand()%10+1, i;
- string gram;
- while(strzal != liczba)
- {
- i++;
- SetConsoleTextAttribute(hConsole, 15); // kolor bialy
- cout << "Strzal nr: " << i << ": ";
- cin >> strzal;
- if(strzal == liczba)
- {
- SetConsoleTextAttribute(hConsole, 10); // kolor zielony
- cout << "Gratulacje! Udalo Ci sie wygrac. Jezeli chcesz zagrac jeszcze raz napisz 'gram'" << endl;
- cout << "A moze chcesz cos policzyc? Napisz wtedy 'kalkulator': ";
- cin >> gram;
- if(gram == "gram") gra();
- else if(gram == "kalkulator") kalkulator();
- else exit(0);
- }
- else if(strzal > liczba)
- {
- SetConsoleTextAttribute(hConsole, 12); // kolor czerwony
- cout << "Za duzo :-(" << endl;
- }
- else if(strzal < liczba)
- {
- SetConsoleTextAttribute(hConsole, 12); // kolor czerwony
- cout << "Za malo :-(" << endl;
- }
- }
- }
- void dalej()
- {
- system("cls");
- SetConsoleTextAttribute(hConsole, 14); // kolor zolty
- cout << " ~MENU~" << endl;
- cout << "Wybierz co chcesz robic dalej :-)" << endl;
- SetConsoleTextAttribute(hConsole, 15); // kolor bialy
- cout << "1. Kalkulator" << endl;
- cout << "2. Gra losowa" << endl;
- char wybierz = getch();
- switch(wybierz)
- {
- case '1':
- {
- kalkulator();
- break;
- }
- case '2':
- {
- gra();
- break;
- }
- }
- }
- int main()
- {
- SetConsoleTextAttribute(hConsole, 14); // kolor zolty
- cout << " WITAJ W PROGRAMIE!" << endl;
- SetConsoleTextAttribute(hConsole, 15); // kolor bialy
- cout << "Zaloguj sie do programu, aby przejsc dalej." << endl << endl;
- SetConsoleTextAttribute(hConsole, 10); // kolor zielony
- cout << "a) Logowanie" << endl;
- cout << "b) Podpowiedz" << endl;
- char menu = getch();
- string login, haslo;
- system("cls");
- switch(menu)
- {
- case 'a':
- {
- podpowiedz:
- cout << "Login: ";
- cin >> login;
- cout << "Haslo: ";
- cin >> haslo;
- if(login == "admin" && haslo == "admin")
- {
- cout << endl <<"Udalo Ci sie zalogowac!" << endl;
- dalej();
- }
- else goto b;
- break;
- }
- case 'b':
- {
- b:
- cout << endl << "admin/admin";
- Sleep(2000);
- system("cls");
- goto podpowiedz;
- break;
- }
- default:
- {
- cout << "Zla opcja!" << endl;
- cout << "Przekierowywanie do logowania..." << endl;
- cout << "3...";
- Sleep(1000);
- cout << "2...";
- Sleep(1000);
- cout << "1...";
- Sleep(1000);
- system("cls");
- goto podpowiedz;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement