Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <cstdlib>
- #include <time.h>
- #include <string>
- using namespace std;
- int numPlayer = 0; int numComp = 0;
- int numCount = 0 ; int numCountTwo = 0;
- char answer;
- void player(int &num1) { //generiranje broja random po referenci za igraca
- num1 += rand() % 21 + 1;
- cout << "\nPlayer has: " << num1 << " points";
- };
- void comp(int &num2) {//generiranje broja random po referenci za komp
- num2+=rand() % 21 + 1;
- cout << "\nComp has: "<<num2<<" points.";
- };
- int main() {
- cout << "WELLCOME TO 21\n\n\n LETS START, press y for play, n for not.\n";
- cin>>answer;
- if (answer == 'y') {
- do//game loop
- {
- srand(static_cast<unsigned int>(time(NULL)));
- cout << "\nHit or stand? ";
- cin >> answer;
- if (answer == 'y') {
- player(numPlayer);
- if (numPlayer > numComp || numComp > 13) { //komp mora imat manji broj, ili manji od 13 da bi igrao
- comp(numComp);
- }
- }
- else if (answer='n') { //ako je odgovor n onda izadi
- if (numPlayer > numComp) {
- cout << "\nPlayer has won\n";
- break;
- return 0;
- }
- else {
- cout << "\nComp has won.\n";
- break;
- return 0;
- }
- }
- //uvjeti za prekid igre!
- // ako je igrac na 21
- if(numPlayer==21){
- cout << "\nWinner is Player, he had: " << numPlayer << " points.\n ";
- break;
- return 0;
- }//Ako je igrac iznad 21 a komp ispod
- else if (numPlayer>21&&numComp<21) {
- cout << "\nYou lose, your num is higher than 21. \n";
- cout << "Comp won, you are loser man\n.";
- break;
- return 0;
- }//ako je komp na 21
- else if (numComp == 21) {
- cout << "\nWinner is Comp, he had: " << numComp << " points.\n";
- break;
- return 0;
- }//ako je komp veci od 21
- else if (numComp > 21) {
- cout << "\nComp has lost.. \n";
- break;
- return 0;
- }//ako su oba iznad 21
- else if(numComp>21&&numPlayer>21){
- cout << "\nYou both lost morons. Don't gamble.\n";
- break;
- return 0;
- }
- } while (!(numPlayer == 21 || numComp == 21)); //!() negacija while petlje, dobio sam untill
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement