Jak to zapisac

0

Mam problem bo chce zapisac to w funkcji ale wyskakuje mi blad

int prawda;
void nazwa()
{
`int firstcard(int maximum, int minimum)
{
    srand(time( NULL ) );
	return rand() % (maximum - minimum + 4);
}

int secondcard(int maximum, int minimum)
{
    srand(time( NULL ) );
	return rand() % (maximum - minimum + 2);
}

int thirdcard(int maximum, int minimum)
{
    srand(time( NULL ) );
	return rand() % (maximum - minimum - 7);
}

int fourcard(int maximum, int minimum)
{
    srand(time( NULL ) );
	return rand() % (maximum - minimum) + minimum + 1;
}
int fivecard(int maximum, int minimum)
{
    srand(time( NULL ) );
	return rand() % (maximum - minimum ) + 5;
    string blad = "BLAD";
   switch(firstcard(54,1))
   {
        case 1:
            cout << "AS KIER\n";
            break;
        case 2:
            cout << "2 KIER\n";
            break;
        case 3:
            cout << "3 KIER\n";
            break;
        case 4:
            cout << "4 KIER\n";
            break;
        case 5:
            cout << "5 KIER\n";
            break;
        case 6:
            cout << "6 KIER\n";
            break;
        case 7:
            cout << "7 KIER\n";
            break;
        case 8:
            cout << "8 KIER\n";
            break;
        case 9:
            cout << "9 KIER\n";
            break;
        case 10:
            cout << "10 KIER\n";
            break;
        case 11:
            cout << "WALET KIER\n";
            break;
        case 12:
            cout << "KROLOWA KIER\n";
            break;
        case 13:
            cout << "KROL KIER\n";
            break;
        case 14:
            cout << "AS PIK\n";
            break;
        case 15:
            cout << "2 PIK\n";
            break;
        case 16:
            cout << "3 PIK\n";
            break;
        case 17:
            cout << "4 PIK\n";
            break;
        case 18:
            cout << "5 PIK\n";
            break;
        case 19:
            cout << "6 PIK\n";
            break;
        case 20:
            cout << "7 PIK\n";
            break;
        case 21:
            cout << "8 PIK\n";
            break;
        case 22:
            cout << "9 PIK\n";
            break;
        case 23:
            cout << "10 PIK\n";
            break;
        case 24:
            cout << "WALET PIK\n";
            break;
        case 25:
            cout << "KROLOWA PIK\n";
            break;
        case 26:
            cout << "KROL PIK\n";
            break;
        case 27:
            cout << "AS TREFL\n";
            break;
        case 28:
            cout << "2 TREFL\n";
            break;
        case 29:
            cout << "3 TREFL\n";
            break;
        case 30:
            cout << "4 TREFL\n";
            break;
        case 31:
            cout << "5 TREFL\n";
            break;
        case 32:
            cout << "6 TREFL\n";
            break;
        case 33:
            cout << "7 TREFL\n";
            break;
        case 34:
            cout << "8 TREFL\n";
            break;
        case 35:
            cout << "9 TREFL\n";
            break;
        case 36:
            cout << "10 TREFL\n";
            break;
        case 37:
            cout << "WALET TREFL\n";
            break;
        case 38:
            cout << "KROLOWA TREFL\n";
            break;
        case 39:
            cout << "KROL TREFL\n";
            break;
        case 40:
            cout << "AS KARO\n";
            break;
        case 41:
            cout << "2 KARO\n";
            break;
        case 42:
            cout << "3 KARO\n";
            break;
        case 43:
            cout << "4 KARO\n";
            break;
        case 44:
            cout << "5 KARO\n";
            break;
        case 45:
            cout << "6 KARO\n";
            break;
        case 46:
            cout << "7 KARO\n";
            break;
        case 47:
            cout << "8 KARO\n";
            break;
        case 48:
            cout << "9 KARO\n";
            break;
        case 49:
            cout << "10 KARO\n";
            break;
        case 50:
            cout << "WALET KARO\n";
            break;
        case 51:
            cout << "KROLOWA KARO\n";
            break;
        case 52:
            cout << "KROL KARO\n";
            break;
        case 53:
            cout << "JOKER CZERWONY\n";
            break;
        case 54:
            cout << "JOKER CZARNY\n";
            break;
        default:
            cout << blad <<'\n';
            prawda = 1;
            break;
   }

      switch(secondcard(54,1))
   {
                case 1:
            cout << "AS KIER\n";
            break;
        case 2:
            cout << "2 KIER\n";
            break;
        case 3:
            cout << "3 KIER\n";
            break;
        case 4:
            cout << "4 KIER\n";
            break;
        case 5:
            cout << "5 KIER\n";
            break;
        case 6:
            cout << "6 KIER\n";
            break;
        case 7:
            cout << "7 KIER\n";
            break;
        case 8:
            cout << "8 KIER\n";
            break;
        case 9:
            cout << "9 KIER\n";
            break;
        case 10:
            cout << "10 KIER\n";
            break;
        case 11:
            cout << "WALET KIER\n";
            break;
        case 12:
            cout << "KROLOWA KIER\n";
            break;
        case 13:
            cout << "KROL KIER\n";
            break;
        case 14:
            cout << "AS PIK\n";
            break;
        case 15:
            cout << "2 PIK\n";
            break;
        case 16:
            cout << "3 PIK\n";
            break;
        case 17:
            cout << "4 PIK\n";
            break;
        case 18:
            cout << "5 PIK\n";
            break;
        case 19:
            cout << "6 PIK\n";
            break;
        case 20:
            cout << "7 PIK\n";
            break;
        case 21:
            cout << "8 PIK\n";
            break;
        case 22:
            cout << "9 PIK\n";
            break;
        case 23:
            cout << "10 PIK\n";
            break;
        case 24:
            cout << "WALET PIK\n";
            break;
        case 25:
            cout << "KROLOWA PIK\n";
            break;
        case 26:
            cout << "KROL PIK\n";
            break;
        case 27:
            cout << "AS TREFL\n";
            break;
        case 28:
            cout << "2 TREFL\n";
            break;
        case 29:
            cout << "3 TREFL\n";
            break;
        case 30:
            cout << "4 TREFL\n";
            break;
        case 31:
            cout << "5 TREFL\n";
            break;
        case 32:
            cout << "6 TREFL\n";
            break;
        case 33:
            cout << "7 TREFL\n";
            break;
        case 34:
            cout << "8 TREFL\n";
            break;
        case 35:
            cout << "9 TREFL\n";
            break;
        case 36:
            cout << "10 TREFL\n";
            break;
        case 37:
            cout << "WALET TREFL\n";
            break;
        case 38:
            cout << "KROLOWA TREFL\n";
            break;
        case 39:
            cout << "KROL TREFL\n";
            break;
        case 40:
            cout << "AS KARO\n";
            break;
        case 41:
            cout << "2 KARO\n";
            break;
        case 42:
            cout << "3 KARO\n";
            break;
        case 43:
            cout << "4 KARO\n";
            break;
        case 44:
            cout << "5 KARO\n";
            break;
        case 45:
            cout << "6 KARO\n";
            break;
        case 46:
            cout << "7 KARO\n";
            break;
        case 47:
            cout << "8 KARO\n";
            break;
        case 48:
            cout << "9 KARO\n";
            break;
        case 49:
            cout << "10 KARO\n";
            break;
        case 50:
            cout << "WALET KARO\n";
            break;
        case 51:
            cout << "KROLOWA KARO\n";
            break;
        case 52:
            cout << "KROL KARO\n";
            break;
        case 53:
            cout << "JOKER CZERWONY\n";
            break;
        case 54:
            cout << "JOKER CZARNY\n";
            break;
        default:
            cout << blad <<'\n';
            prawda = 1;
            break;
   }
      switch(thirdcard(54,1))
   {
                case 1:
            cout << "AS KIER\n";
            break;
        case 2:
            cout << "2 KIER\n";
            break;
        case 3:
            cout << "3 KIER\n";
            break;
        case 4:
            cout << "4 KIER\n";
            break;
        case 5:
            cout << "5 KIER\n";
            break;
        case 6:
            cout << "6 KIER\n";
            break;
        case 7:
            cout << "7 KIER\n";
            break;
        case 8:
            cout << "8 KIER\n";
            break;
        case 9:
            cout << "9 KIER\n";
            break;
        case 10:
            cout << "10 KIER\n";
            break;
        case 11:
            cout << "WALET KIER\n";
            break;
        case 12:
            cout << "KROLOWA KIER\n";
            break;
        case 13:
            cout << "KROL KIER\n";
            break;
        case 14:
            cout << "AS PIK\n";
            break;
        case 15:
            cout << "2 PIK\n";
            break;
        case 16:
            cout << "3 PIK\n";
            break;
        case 17:
            cout << "4 PIK\n";
            break;
        case 18:
            cout << "5 PIK\n";
            break;
        case 19:
            cout << "6 PIK\n";
            break;
        case 20:
            cout << "7 PIK\n";
            break;
        case 21:
            cout << "8 PIK\n";
            break;
        case 22:
            cout << "9 PIK\n";
            break;
        case 23:
            cout << "10 PIK\n";
            break;
        case 24:
            cout << "WALET PIK\n";
            break;
        case 25:
            cout << "KROLOWA PIK\n";
            break;
        case 26:
            cout << "KROL PIK\n";
            break;
        case 27:
            cout << "AS TREFL\n";
            break;
        case 28:
            cout << "2 TREFL\n";
            break;
        case 29:
            cout << "3 TREFL\n";
            break;
        case 30:
            cout << "4 TREFL\n";
            break;
        case 31:
            cout << "5 TREFL\n";
            break;
        case 32:
            cout << "6 TREFL\n";
            break;
        case 33:
            cout << "7 TREFL\n";
            break;
        case 34:
            cout << "8 TREFL\n";
            break;
        case 35:
            cout << "9 TREFL\n";
            break;
        case 36:
            cout << "10 TREFL\n";
            break;
        case 37:
            cout << "WALET TREFL\n";
            break;
        case 38:
            cout << "KROLOWA TREFL\n";
            break;
        case 39:
            cout << "KROL TREFL\n";
            break;
        case 40:
            cout << "AS KARO\n";
            break;
        case 41:
            cout << "2 KARO\n";
            break;
        case 42:
            cout << "3 KARO\n";
            break;
        case 43:
            cout << "4 KARO\n";
            break;
        case 44:
            cout << "5 KARO\n";
            break;
        case 45:
            cout << "6 KARO\n";
            break;
        case 46:
            cout << "7 KARO\n";
            break;
        case 47:
            cout << "8 KARO\n";
            break;
        case 48:
            cout << "9 KARO\n";
            break;
        case 49:
            cout << "10 KARO\n";
            break;
        case 50:
            cout << "WALET KARO\n";
            break;
        case 51:
            cout << "KROLOWA KARO\n";
            break;
        case 52:
            cout << "KROL KARO\n";
            break;
        case 53:
            cout << "JOKER CZERWONY\n";
            break;
        case 54:
            cout << "JOKER CZARNY\n";
            break;
        default:
            cout << blad <<'\n';
            prawda = 1;
            break;
   }
      switch(fourcard(54,1))
   {
                case 1:
            cout << "AS KIER\n";
            break;
        case 2:
            cout << "2 KIER\n";
            break;
        case 3:
            cout << "3 KIER\n";
            break;
        case 4:
            cout << "4 KIER\n";
            break;
        case 5:
            cout << "5 KIER\n";
            break;
        case 6:
            cout << "6 KIER\n";
            break;
        case 7:
            cout << "7 KIER\n";
            break;
        case 8:
            cout << "8 KIER\n";
            break;
        case 9:
            cout << "9 KIER\n";
            break;
        case 10:
            cout << "10 KIER\n";
            break;
        case 11:
            cout << "WALET KIER\n";
            break;
        case 12:
            cout << "KROLOWA KIER\n";
            break;
        case 13:
            cout << "KROL KIER\n";
            break;
        case 14:
            cout << "AS PIK\n";
            break;
        case 15:
            cout << "2 PIK\n";
            break;
        case 16:
            cout << "3 PIK\n";
            break;
        case 17:
            cout << "4 PIK\n";
            break;
        case 18:
            cout << "5 PIK\n";
            break;
        case 19:
            cout << "6 PIK\n";
            break;
        case 20:
            cout << "7 PIK\n";
            break;
        case 21:
            cout << "8 PIK\n";
            break;
        case 22:
            cout << "9 PIK\n";
            break;
        case 23:
            cout << "10 PIK\n";
            break;
        case 24:
            cout << "WALET PIK\n";
            break;
        case 25:
            cout << "KROLOWA PIK\n";
            break;
        case 26:
            cout << "KROL PIK\n";
            break;
        case 27:
            cout << "AS TREFL\n";
            break;
        case 28:
            cout << "2 TREFL\n";
            break;
        case 29:
            cout << "3 TREFL\n";
            break;
        case 30:
            cout << "4 TREFL\n";
            break;
        case 31:
            cout << "5 TREFL\n";
            break;
        case 32:
            cout << "6 TREFL\n";
            break;
        case 33:
            cout << "7 TREFL\n";
            break;
        case 34:
            cout << "8 TREFL\n";
            break;
        case 35:
            cout << "9 TREFL\n";
            break;
        case 36:
            cout << "10 TREFL\n";
            break;
        case 37:
            cout << "WALET TREFL\n";
            break;
        case 38:
            cout << "KROLOWA TREFL\n";
            break;
        case 39:
            cout << "KROL TREFL\n";
            break;
        case 40:
            cout << "AS KARO\n";
            break;
        case 41:
            cout << "2 KARO\n";
            break;
        case 42:
            cout << "3 KARO\n";
            break;
        case 43:
            cout << "4 KARO\n";
            break;
        case 44:
            cout << "5 KARO\n";
            break;
        case 45:
            cout << "6 KARO\n";
            break;
        case 46:
            cout << "7 KARO\n";
            break;
        case 47:
            cout << "8 KARO\n";
            break;
        case 48:
            cout << "9 KARO\n";
            break;
        case 49:
            cout << "10 KARO\n";
            break;
        case 50:
            cout << "WALET KARO\n";
            break;
        case 51:
            cout << "KROLOWA KARO\n";
            break;
        case 52:
            cout << "KROL KARO\n";
            break;
        case 53:
            cout << "JOKER CZERWONY\n";
            break;
        case 54:
            cout << "JOKER CZARNY\n";
            break;
        default:
            cout << blad <<'\n';
            prawda = 1;
            break;
   }

      switch(fivecard(54,1))
   {
                case 1:
            cout << "AS KIER\n";
            break;
        case 2:
            cout << "2 KIER\n";
            break;
        case 3:
            cout << "3 KIER\n";
            break;
        case 4:
            cout << "4 KIER\n";
            break;
        case 5:
            cout << "5 KIER\n";
            break;
        case 6:
            cout << "6 KIER\n";
            break;
        case 7:
            cout << "7 KIER\n";
            break;
        case 8:
            cout << "8 KIER\n";
            break;
        case 9:
            cout << "9 KIER\n";
            break;
        case 10:
            cout << "10 KIER\n";
            break;
        case 11:
            cout << "WALET KIER\n";
            break;
        case 12:
            cout << "KROLOWA KIER\n";
            break;
        case 13:
            cout << "KROL KIER\n";
            break;
        case 14:
            cout << "AS PIK\n";
            break;
        case 15:
            cout << "2 PIK\n";
            break;
        case 16:
            cout << "3 PIK\n";
            break;
        case 17:
            cout << "4 PIK\n";
            break;
        case 18:
            cout << "5 PIK\n";
            break;
        case 19:
            cout << "6 PIK\n";
            break;
        case 20:
            cout << "7 PIK\n";
            break;
        case 21:
            cout << "8 PIK\n";
            break;
        case 22:
            cout << "9 PIK\n";
            break;
        case 23:
            cout << "10 PIK\n";
            break;
        case 24:
            cout << "WALET PIK\n";
            break;
        case 25:
            cout << "KROLOWA PIK\n";
            break;
        case 26:
            cout << "KROL PIK\n";
            break;
        case 27:
            cout << "AS TREFL\n";
            break;
        case 28:
            cout << "2 TREFL\n";
            break;
        case 29:
            cout << "3 TREFL\n";
            break;
        case 30:
            cout << "4 TREFL\n";
            break;
        case 31:
            cout << "5 TREFL\n";
            break;
        case 32:
            cout << "6 TREFL\n";
            break;
        case 33:
            cout << "7 TREFL\n";
            break;
        case 34:
            cout << "8 TREFL\n";
            break;
        case 35:
            cout << "9 TREFL\n";
            break;
        case 36:
            cout << "10 TREFL\n";
            break;
        case 37:
            cout << "WALET TREFL\n";
            break;
        case 38:
            cout << "KROLOWA TREFL\n";
            break;
        case 39:
            cout << "KROL TREFL\n";
            break;
        case 40:
            cout << "AS KARO\n";
            break;
        case 41:
            cout << "2 KARO\n";
            break;
        case 42:
            cout << "3 KARO\n";
            break;
        case 43:
            cout << "4 KARO\n";
            break;
        case 44:
            cout << "5 KARO\n";
            break;
        case 45:
            cout << "6 KARO\n";
            break;
        case 46:
            cout << "7 KARO\n";
            break;
        case 47:
            cout << "8 KARO\n";
            break;
        case 48:
            cout << "9 KARO\n";
            break;
        case 49:
            cout << "10 KARO\n";
            break;
        case 50:
            cout << "WALET KARO\n";
            break;
        case 51:
            cout << "KROLOWA KARO\n";
            break;
        case 52:
            cout << "KROL KARO\n";
            break;
        case 53:
            cout << "JOKER CZERWONY\n";
            break;
        case 54:
            cout << "JOKER CZARNY\n";
            break;
        default:
            cout << blad <<'\n';
            prawda = 1;
            break;
   }
}
2

ale wyskakuje mi blad

Jaki błąd?

1

error: a function-definition is not allowed here before '{' token

taki blad

1


1

Definiujesz funkcję wewnątrz funkcji

int prawda;
void nazwa()
{
int firstcard(int maximum, int minimum)
{
srand(time( NULL ) );
return rand() % (maximum - minimum + 4);
}
1

chcĘ podkreslic ze sie dopiero ucze

1

nie rozumiem mozesz mi wytlumaczyc

Nie możesz definiować funkcji wewnątrz innej funkcji. Wskazałem Ci miejsce w którym to się dzieje.

1

a jak juz o programowaniu to powie mi ktos co zrobic by mi sie ta funkcja int aktalizowala

0
#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;


int firstcard(int maximum, int minimum)
{
    srand(time( NULL ) );
	return rand() % (maximum - minimum + 4);
}

int secondcard(int maximum, int minimum)
{
    srand(time( NULL ) );
	return rand() % (maximum - minimum + 2);
}

int thirdcard(int maximum, int minimum)
{
    srand(time( NULL ) );
	return rand() % (maximum - minimum - 7);
}

int fourcard(int maximum, int minimum)
{
    srand(time( NULL ) );
	return rand() % (maximum - minimum) + minimum + 1;
}
int fivecard(int maximum, int minimum)
{
    srand(time( NULL ) );
	return rand() % (maximum - minimum ) + 5;
}
string blad = "BLAD";
int prawda;
void nazwa()
{
    firstcard(54,1);
    secondcard(54,1);
    thirdcard(54,1);
    fourcard(54,1);
    fivecard(54,1);
    switch(firstcard(54,1))
   {
        case 1:
            cout << "AS KIER\n";
            break;
        case 2:
            cout << "2 KIER\n";
            break;
        case 3:
            cout << "3 KIER\n";
            break;
        case 4:
            cout << "4 KIER\n";
            break;
        case 5:
            cout << "5 KIER\n";
            break;
        case 6:
            cout << "6 KIER\n";
            break;
        case 7:
            cout << "7 KIER\n";
            break;
        case 8:
            cout << "8 KIER\n";
            break;
        case 9:
            cout << "9 KIER\n";
            break;
        case 10:
            cout << "10 KIER\n";
            break;
        case 11:
            cout << "WALET KIER\n";
            break;
        case 12:
            cout << "KROLOWA KIER\n";
            break;
        case 13:
            cout << "KROL KIER\n";
            break;
        case 14:
            cout << "AS PIK\n";
            break;
        case 15:
            cout << "2 PIK\n";
            break;
        case 16:
            cout << "3 PIK\n";
            break;
        case 17:
            cout << "4 PIK\n";
            break;
        case 18:
            cout << "5 PIK\n";
            break;
        case 19:
            cout << "6 PIK\n";
            break;
        case 20:
            cout << "7 PIK\n";
            break;
        case 21:
            cout << "8 PIK\n";
            break;
        case 22:
            cout << "9 PIK\n";
            break;
        case 23:
            cout << "10 PIK\n";
            break;
        case 24:
            cout << "WALET PIK\n";
            break;
        case 25:
            cout << "KROLOWA PIK\n";
            break;
        case 26:
            cout << "KROL PIK\n";
            break;
        case 27:
            cout << "AS TREFL\n";
            break;
        case 28:
            cout << "2 TREFL\n";
            break;
        case 29:
            cout << "3 TREFL\n";
            break;
        case 30:
            cout << "4 TREFL\n";
            break;
        case 31:
            cout << "5 TREFL\n";
            break;
        case 32:
            cout << "6 TREFL\n";
            break;
        case 33:
            cout << "7 TREFL\n";
            break;
        case 34:
            cout << "8 TREFL\n";
            break;
        case 35:
            cout << "9 TREFL\n";
            break;
        case 36:
            cout << "10 TREFL\n";
            break;
        case 37:
            cout << "WALET TREFL\n";
            break;
        case 38:
            cout << "KROLOWA TREFL\n";
            break;
        case 39:
            cout << "KROL TREFL\n";
            break;
        case 40:
            cout << "AS KARO\n";
            break;
        case 41:
            cout << "2 KARO\n";
            break;
        case 42:
            cout << "3 KARO\n";
            break;
        case 43:
            cout << "4 KARO\n";
            break;
        case 44:
            cout << "5 KARO\n";
            break;
        case 45:
            cout << "6 KARO\n";
            break;
        case 46:
            cout << "7 KARO\n";
            break;
        case 47:
            cout << "8 KARO\n";
            break;
        case 48:
            cout << "9 KARO\n";
            break;
        case 49:
            cout << "10 KARO\n";
            break;
        case 50:
            cout << "WALET KARO\n";
            break;
        case 51:
            cout << "KROLOWA KARO\n";
            break;
        case 52:
            cout << "KROL KARO\n";
            break;
        case 53:
            cout << "JOKER CZERWONY\n";
            break;
        case 54:
            cout << "JOKER CZARNY\n";
            break;
        default:
            cout << blad <<'\n';
            prawda = 1;
            break;
   }

      switch(secondcard(54,1))
   {
                case 1:
            cout << "AS KIER\n";
            break;
        case 2:
            cout << "2 KIER\n";
            break;
        case 3:
            cout << "3 KIER\n";
            break;
        case 4:
            cout << "4 KIER\n";
            break;
        case 5:
            cout << "5 KIER\n";
            break;
        case 6:
            cout << "6 KIER\n";
            break;
        case 7:
            cout << "7 KIER\n";
            break;
        case 8:
            cout << "8 KIER\n";
            break;
        case 9:
            cout << "9 KIER\n";
            break;
        case 10:
            cout << "10 KIER\n";
            break;
        case 11:
            cout << "WALET KIER\n";
            break;
        case 12:
            cout << "KROLOWA KIER\n";
            break;
        case 13:
            cout << "KROL KIER\n";
            break;
        case 14:
            cout << "AS PIK\n";
            break;
        case 15:
            cout << "2 PIK\n";
            break;
        case 16:
            cout << "3 PIK\n";
            break;
        case 17:
            cout << "4 PIK\n";
            break;
        case 18:
            cout << "5 PIK\n";
            break;
        case 19:
            cout << "6 PIK\n";
            break;
        case 20:
            cout << "7 PIK\n";
            break;
        case 21:
            cout << "8 PIK\n";
            break;
        case 22:
            cout << "9 PIK\n";
            break;
        case 23:
            cout << "10 PIK\n";
            break;
        case 24:
            cout << "WALET PIK\n";
            break;
        case 25:
            cout << "KROLOWA PIK\n";
            break;
        case 26:
            cout << "KROL PIK\n";
            break;
        case 27:
            cout << "AS TREFL\n";
            break;
        case 28:
            cout << "2 TREFL\n";
            break;
        case 29:
            cout << "3 TREFL\n";
            break;
        case 30:
            cout << "4 TREFL\n";
            break;
        case 31:
            cout << "5 TREFL\n";
            break;
        case 32:
            cout << "6 TREFL\n";
            break;
        case 33:
            cout << "7 TREFL\n";
            break;
        case 34:
            cout << "8 TREFL\n";
            break;
        case 35:
            cout << "9 TREFL\n";
            break;
        case 36:
            cout << "10 TREFL\n";
            break;
        case 37:
            cout << "WALET TREFL\n";
            break;
        case 38:
            cout << "KROLOWA TREFL\n";
            break;
        case 39:
            cout << "KROL TREFL\n";
            break;
        case 40:
            cout << "AS KARO\n";
            break;
        case 41:
            cout << "2 KARO\n";
            break;
        case 42:
            cout << "3 KARO\n";
            break;
        case 43:
            cout << "4 KARO\n";
            break;
        case 44:
            cout << "5 KARO\n";
            break;
        case 45:
            cout << "6 KARO\n";
            break;
        case 46:
            cout << "7 KARO\n";
            break;
        case 47:
            cout << "8 KARO\n";
            break;
        case 48:
            cout << "9 KARO\n";
            break;
        case 49:
            cout << "10 KARO\n";
            break;
        case 50:
            cout << "WALET KARO\n";
            break;
        case 51:
            cout << "KROLOWA KARO\n";
            break;
        case 52:
            cout << "KROL KARO\n";
            break;
        case 53:
            cout << "JOKER CZERWONY\n";
            break;
        case 54:
            cout << "JOKER CZARNY\n";
            break;
        default:
            cout << blad <<'\n';
            prawda = 1;
            break;
   }
      switch(thirdcard(54,1))
   {
                case 1:
            cout << "AS KIER\n";
            break;
        case 2:
            cout << "2 KIER\n";
            break;
        case 3:
            cout << "3 KIER\n";
            break;
        case 4:
            cout << "4 KIER\n";
            break;
        case 5:
            cout << "5 KIER\n";
            break;
        case 6:
            cout << "6 KIER\n";
            break;
        case 7:
            cout << "7 KIER\n";
            break;
        case 8:
            cout << "8 KIER\n";
            break;
        case 9:
            cout << "9 KIER\n";
            break;
        case 10:
            cout << "10 KIER\n";
            break;
        case 11:
            cout << "WALET KIER\n";
            break;
        case 12:
            cout << "KROLOWA KIER\n";
            break;
        case 13:
            cout << "KROL KIER\n";
            break;
        case 14:
            cout << "AS PIK\n";
            break;
        case 15:
            cout << "2 PIK\n";
            break;
        case 16:
            cout << "3 PIK\n";
            break;
        case 17:
            cout << "4 PIK\n";
            break;
        case 18:
            cout << "5 PIK\n";
            break;
        case 19:
            cout << "6 PIK\n";
            break;
        case 20:
            cout << "7 PIK\n";
            break;
        case 21:
            cout << "8 PIK\n";
            break;
        case 22:
            cout << "9 PIK\n";
            break;
        case 23:
            cout << "10 PIK\n";
            break;
        case 24:
            cout << "WALET PIK\n";
            break;
        case 25:
            cout << "KROLOWA PIK\n";
            break;
        case 26:
            cout << "KROL PIK\n";
            break;
        case 27:
            cout << "AS TREFL\n";
            break;
        case 28:
            cout << "2 TREFL\n";
            break;
        case 29:
            cout << "3 TREFL\n";
            break;
        case 30:
            cout << "4 TREFL\n";
            break;
        case 31:
            cout << "5 TREFL\n";
            break;
        case 32:
            cout << "6 TREFL\n";
            break;
        case 33:
            cout << "7 TREFL\n";
            break;
        case 34:
            cout << "8 TREFL\n";
            break;
        case 35:
            cout << "9 TREFL\n";
            break;
        case 36:
            cout << "10 TREFL\n";
            break;
        case 37:
            cout << "WALET TREFL\n";
            break;
        case 38:
            cout << "KROLOWA TREFL\n";
            break;
        case 39:
            cout << "KROL TREFL\n";
            break;
        case 40:
            cout << "AS KARO\n";
            break;
        case 41:
            cout << "2 KARO\n";
            break;
        case 42:
            cout << "3 KARO\n";
            break;
        case 43:
            cout << "4 KARO\n";
            break;
        case 44:
            cout << "5 KARO\n";
            break;
        case 45:
            cout << "6 KARO\n";
            break;
        case 46:
            cout << "7 KARO\n";
            break;
        case 47:
            cout << "8 KARO\n";
            break;
        case 48:
            cout << "9 KARO\n";
            break;
        case 49:
            cout << "10 KARO\n";
            break;
        case 50:
            cout << "WALET KARO\n";
            break;
        case 51:
            cout << "KROLOWA KARO\n";
            break;
        case 52:
            cout << "KROL KARO\n";
            break;
        case 53:
            cout << "JOKER CZERWONY\n";
            break;
        case 54:
            cout << "JOKER CZARNY\n";
            break;
        default:
            cout << blad <<'\n';
            prawda = 1;
            break;
   }
      switch(fourcard(54,1))
   {
                case 1:
            cout << "AS KIER\n";
            break;
        case 2:
            cout << "2 KIER\n";
            break;
        case 3:
            cout << "3 KIER\n";
            break;
        case 4:
            cout << "4 KIER\n";
            break;
        case 5:
            cout << "5 KIER\n";
            break;
        case 6:
            cout << "6 KIER\n";
            break;
        case 7:
            cout << "7 KIER\n";
            break;
        case 8:
            cout << "8 KIER\n";
            break;
        case 9:
            cout << "9 KIER\n";
            break;
        case 10:
            cout << "10 KIER\n";
            break;
        case 11:
            cout << "WALET KIER\n";
            break;
        case 12:
            cout << "KROLOWA KIER\n";
            break;
        case 13:
            cout << "KROL KIER\n";
            break;
        case 14:
            cout << "AS PIK\n";
            break;
        case 15:
            cout << "2 PIK\n";
            break;
        case 16:
            cout << "3 PIK\n";
            break;
        case 17:
            cout << "4 PIK\n";
            break;
        case 18:
            cout << "5 PIK\n";
            break;
        case 19:
            cout << "6 PIK\n";
            break;
        case 20:
            cout << "7 PIK\n";
            break;
        case 21:
            cout << "8 PIK\n";
            break;
        case 22:
            cout << "9 PIK\n";
            break;
        case 23:
            cout << "10 PIK\n";
            break;
        case 24:
            cout << "WALET PIK\n";
            break;
        case 25:
            cout << "KROLOWA PIK\n";
            break;
        case 26:
            cout << "KROL PIK\n";
            break;
        case 27:
            cout << "AS TREFL\n";
            break;
        case 28:
            cout << "2 TREFL\n";
            break;
        case 29:
            cout << "3 TREFL\n";
            break;
        case 30:
            cout << "4 TREFL\n";
            break;
        case 31:
            cout << "5 TREFL\n";
            break;
        case 32:
            cout << "6 TREFL\n";
            break;
        case 33:
            cout << "7 TREFL\n";
            break;
        case 34:
            cout << "8 TREFL\n";
            break;
        case 35:
            cout << "9 TREFL\n";
            break;
        case 36:
            cout << "10 TREFL\n";
            break;
        case 37:
            cout << "WALET TREFL\n";
            break;
        case 38:
            cout << "KROLOWA TREFL\n";
            break;
        case 39:
            cout << "KROL TREFL\n";
            break;
        case 40:
            cout << "AS KARO\n";
            break;
        case 41:
            cout << "2 KARO\n";
            break;
        case 42:
            cout << "3 KARO\n";
            break;
        case 43:
            cout << "4 KARO\n";
            break;
        case 44:
            cout << "5 KARO\n";
            break;
        case 45:
            cout << "6 KARO\n";
            break;
        case 46:
            cout << "7 KARO\n";
            break;
        case 47:
            cout << "8 KARO\n";
            break;
        case 48:
            cout << "9 KARO\n";
            break;
        case 49:
            cout << "10 KARO\n";
            break;
        case 50:
            cout << "WALET KARO\n";
            break;
        case 51:
            cout << "KROLOWA KARO\n";
            break;
        case 52:
            cout << "KROL KARO\n";
            break;
        case 53:
            cout << "JOKER CZERWONY\n";
            break;
        case 54:
            cout << "JOKER CZARNY\n";
            break;
        default:
            cout << blad <<'\n';
            prawda = 1;
            break;
   }

      switch(fivecard(54,1))
   {
                case 1:
            cout << "AS KIER\n";
            break;
        case 2:
            cout << "2 KIER\n";
            break;
        case 3:
            cout << "3 KIER\n";
            break;
        case 4:
            cout << "4 KIER\n";
            break;
        case 5:
            cout << "5 KIER\n";
            break;
        case 6:
            cout << "6 KIER\n";
            break;
        case 7:
            cout << "7 KIER\n";
            break;
        case 8:
            cout << "8 KIER\n";
            break;
        case 9:
            cout << "9 KIER\n";
            break;
        case 10:
            cout << "10 KIER\n";
            break;
        case 11:
            cout << "WALET KIER\n";
            break;
        case 12:
            cout << "KROLOWA KIER\n";
            break;
        case 13:
            cout << "KROL KIER\n";
            break;
        case 14:
            cout << "AS PIK\n";
            break;
        case 15:
            cout << "2 PIK\n";
            break;
        case 16:
            cout << "3 PIK\n";
            break;
        case 17:
            cout << "4 PIK\n";
            break;
        case 18:
            cout << "5 PIK\n";
            break;
        case 19:
            cout << "6 PIK\n";
            break;
        case 20:
            cout << "7 PIK\n";
            break;
        case 21:
            cout << "8 PIK\n";
            break;
        case 22:
            cout << "9 PIK\n";
            break;
        case 23:
            cout << "10 PIK\n";
            break;
        case 24:
            cout << "WALET PIK\n";
            break;
        case 25:
            cout << "KROLOWA PIK\n";
            break;
        case 26:
            cout << "KROL PIK\n";
            break;
        case 27:
            cout << "AS TREFL\n";
            break;
        case 28:
            cout << "2 TREFL\n";
            break;
        case 29:
            cout << "3 TREFL\n";
            break;
        case 30:
            cout << "4 TREFL\n";
            break;
        case 31:
            cout << "5 TREFL\n";
            break;
        case 32:
            cout << "6 TREFL\n";
            break;
        case 33:
            cout << "7 TREFL\n";
            break;
        case 34:
            cout << "8 TREFL\n";
            break;
        case 35:
            cout << "9 TREFL\n";
            break;
        case 36:
            cout << "10 TREFL\n";
            break;
        case 37:
            cout << "WALET TREFL\n";
            break;
        case 38:
            cout << "KROLOWA TREFL\n";
            break;
        case 39:
            cout << "KROL TREFL\n";
            break;
        case 40:
            cout << "AS KARO\n";
            break;
        case 41:
            cout << "2 KARO\n";
            break;
        case 42:
            cout << "3 KARO\n";
            break;
        case 43:
            cout << "4 KARO\n";
            break;
        case 44:
            cout << "5 KARO\n";
            break;
        case 45:
            cout << "6 KARO\n";
            break;
        case 46:
            cout << "7 KARO\n";
            break;
        case 47:
            cout << "8 KARO\n";
            break;
        case 48:
            cout << "9 KARO\n";
            break;
        case 49:
            cout << "10 KARO\n";
            break;
        case 50:
            cout << "WALET KARO\n";
            break;
        case 51:
            cout << "KROLOWA KARO\n";
            break;
        case 52:
            cout << "KROL KARO\n";
            break;
        case 53:
            cout << "JOKER CZERWONY\n";
            break;
        case 54:
            cout << "JOKER CZARNY\n";
            break;
        default:
            cout << blad <<'\n';
            prawda = 1;
            break;
   }
}
int main()
{
     nazwa();
     if ( firstcard(54,1) == secondcard(54,1) || firstcard(54,1) == thirdcard(54,1) || firstcard(54,1) == fourcard(54,1) || firstcard(54,1) == fivecard(54,1) || secondcard(54,1) == thirdcard(54,1) || secondcard(54,1) == fourcard(54,1) || secondcard(54,1) == fivecard(54,1) || thirdcard(54,1) == fourcard(54,1) || thirdcard(54,1) == fivecard(54,1) || fourcard(54,1) == fivecard(54,1) )
     {
        cout << '\n';
        nazwa();
     }
     if ( prawda == 1)
     {
         cout << '\n';
         nazwa();
     }
}


0

Popatrz, tak to zrób:
c++ Tutaj wklejasz swój kod

1

juz jest dobrze dzieki za info ze tak sie da

to tak mamint firstcard i chce gdy na konsoli pokarze sie blad to ma sie wlaczy program jeszcze raz i wylosowac nowe liczbe

@Suchy702: o to chodzi

0

Okej, teraz rozumiem co chcesz osiągnąć. Musisz zrobić pętle, np. z użyciem while:

string odpowiedz_od_uzytkownika;
cin >> odpowiedz_od_uzytkownika;
while (sprawdz_czy_odpowiedz_jest_poprawna(odpowiedz_od_uzytkownika)) {
    cout << "BLAD! Podales zla odpowiedz!\n";
    
    cout << "Muszę znowu wczytać od ciebie odpowiedz, nie denerwuj mnie i podaj ją poprawnie!\n";
    cin >> odpowiedz_od_uzytkownika;
}

//tutaj jestesmy, jesli uzytkownik dal dobra odpowiedz
cout << "Okej teraz możesz przejść do dalszej części mojego programu\n";
0

zaraz zobacze w rzaie wodpliweosci bede pisal

0

error: expected unqualified-id before 'while'
wyskakuje mi taki blad

0
while
{
int firstcard(int maximum, int minimum)
{
    srand(time( NULL ) );
	return rand() % (maximum - minimum + 4);
}

int secondcard(int maximum, int minimum)
{
    srand(time( NULL ) );
	return rand() % (maximum - minimum + 2);
}

int thirdcard(int maximum, int minimum)
{
    srand(time( NULL ) );
	return rand() % (maximum - minimum - 7);
}

int fourcard(int maximum, int minimum)
{
    srand(time( NULL ) );
	return rand() % (maximum - minimum) + minimum + 1;
}
int fivecard(int maximum, int minimum)
{
    srand(time( NULL ) );
	return rand() % (maximum - minimum ) + 5;
}
}

0

dziekuje mam nadzieje ze kto odpisze do jutra

0

Nie, nie, źle myślisz. Twoje przykładowo:

int firstcard(int maximum, int minimum)
{
    srand(time( NULL ) );
    return rand() % (maximum - minimum + 4);
}

to definicja funkcji - mówisz tutaj kompilatorowi, że ma stworzyć funkcję, która się będzie nazywać "firstcard" i kiedyś w przyszłości będziesz tego używał. Ale to nie jest użycie (wykorzystanie), tylko definicja, dlatego wrzucenie tego do środka while nie ma sensu - wszystkie takie firstcard czy inne secondcard muszą po prostu być gdzieś poza innymi funkcjami. Z kolei kiedy robisz sobie na przykład:

int main()
{
     nazwa();
// i tak dalej

To tutaj z kolei (wewnątrz funkcji main) uruchamiasz swoją, wcześniej zdefiniowaną, funkcję nazwa. Uruchamianie możesz obejmować w pętle i inne tego typu rzeczy, definicji nie możesz (to nie ma za bardzo sensu). Aby się ponownie losowały rzeczy to tego while musisz użyć gdzieś we wnętrzu main() - na przykład tak jak masz w poście nieco wyżej.

4

O Swarogu, Perunie, Trygławie i Welesie, widzicie i nie grzmicie...
Bracie @StachuBond9 co ty za program chcesz stworzyć? Weź go opisz, bo choć słuszne na tym forum jest zapodawanie kodu zawierającego co już udało się stworzyć to od patrzenia na twój krwawią oczy.

4
  1. srand(time( NULL ) ); ma być wywołane tylko raz na początku programu (pogooglaj sobie czemu) - wielokrotne wywołanie będzie powodować, że wyniki się będą czasami powtarzać.
  2. Podziel opis karty na cześci (dwa pola) jedno opisujące kolor i jedno opisujące figurę
  3. Zamiast switch użyj tablicy - będzie czytelniej.
#include <iostream>
#include <array>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cassert>

using namespace std::literals;

enum class CardSuit {
     Spades, 
     Hearts,
     Diamonds,
     Clubs, 
};

struct Card {
     CardSuit suit;
     int rank;
};

using Deck = std::vector<Card>;

constexpr size_t RankSize = 13;
constexpr size_t SuitesCount = 4;
constexpr size_t DeckSize = RankSize * SuitesCount;
constexpr int BottomRankAs = 2;
constexpr int TopRankAs = 14;

std::ostream& operator<<(std::ostream& out, Card card) {
    constexpr std::array<std::string_view, RankSize> rankNames {
          "2"sv,
          "3"sv,
          "4"sv,
          "5"sv,
          "6"sv,
          "7"sv,
          "8"sv,
          "9"sv,
          "10"sv,
          "Walet"sv,
          "Dama"sv,
          "Król"sv,
          "As"sv,
    };
    constexpr std::array<std::string_view, SuitesCount> suitNames {
          "Pik"sv,
          "Kier"sv,
          "Karo"sv,
          "Trefl"sv,
    };

    out << rankNames.at(card.rank - BottomRankAs) << ' ';
    out << suitNames.at(static_cast<size_t>(card.suit));

    return out;
}

template<typename Out>
Out fillAllCardsWithSuit(Out b, CardSuit suit) {
    Card card{suit, BottomRankAs - 1};
    return std::generate_n(b, RankSize,[&card]() {
        ++card.rank;
        assert(card.rank >= BottomRankAs);
        assert(card.rank <= TopRankAs);
        return card;
    });
}

std::vector<Card> makeFullDeck() {
    std::vector<Card> deck;
    deck.reserve(DeckSize);
    fillAllCardsWithSuit(std::back_inserter(deck), CardSuit::Spades);
    fillAllCardsWithSuit(std::back_inserter(deck), CardSuit::Hearts);
    fillAllCardsWithSuit(std::back_inserter(deck), CardSuit::Diamonds);
    fillAllCardsWithSuit(std::back_inserter(deck), CardSuit::Clubs);
    assert(deck.size() == DeckSize);
    return deck;
}

std::ostream& operator<<(std::ostream& out, const Deck& deck) {
    for(auto& card : deck) {
        out << card << ", ";
    }
    return out;
}

int main()
{
    auto deck = makeFullDeck();
    std::cout << deck << '\n';
    std::random_shuffle(deck.begin(), deck.end());
    std::cout << deck << '\n';

    return 0;
}

https://godbolt.org/z/8jMMTzjE9

Zarejestruj się i dołącz do największej społeczności programistów w Polsce.

Otrzymaj wsparcie, dziel się wiedzą i rozwijaj swoje umiejętności z najlepszymi.