• 0
Sign in to follow this  
Victor Vinicios

CÓDIGO EM C SOBRE CARTAS

Question

SEGUINTE PROBLEMA !!!! MONTEI MEU CODIGO porém ELE ESTA RETORNADO CARACTERES OU NUMEROS ALEATORIOS NO LUGAR DAS CARTAS O  QUE ESTA ERRADO ???:tw_confounded:

(Escolha um jogo de cartas, baseado em um “baralho tradicional” (cada carta tem seu naipe e seu valor). Implemente a parte de distribuição (sorteio) de cartas para 2 jogadores, considerando que cada jogador ira receber 5 cartas. Exiba na tela as cartas que cada um dos jogadores recebeu.)

***********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************

 

#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<time.h>

typedef struct{
    char naipe[10];
    int valor;
}cartas;
int main(){
    
    cartas carta[51];
    char naipe[12]= "Copas";
    char naipe2[12]="Espadas";
    char naipe3[12]="Paus";
    char naipe4[12]="Ouros";
    int i, n, n2;
    srand(time(NULL));
//========================================================================================//    
    for(i=0;i>=12; i++){
        carta.valor=i-1;
        strcpy(carta.naipe, naipe);
    }
    for(i=13; i<=25; i++){
        carta.valor=i-12;
        strcpy(carta.naipe, naipe2);
    }
    for(i=26; i<=38; i++){        
        carta.valor=i-25;
        strcpy(carta.naipe, naipe3);
    }
    for(i=39; i>=51; i++){
        carta.valor=i-51;
        strcpy(carta.naipe, naipe4);
    }    
//========================================================================================//
    printf("Joao recebera:\n");
    for(i=0; i<5;i++){
        n=rand()%51;
        printf("\n%d de %s", carta[n].valor, carta[n].naipe);
    }
    printf("\n\nMaria recebera:\n");
    for(i=0; i<5;i++){
        n2=rand()%50;
        printf("\n%d de %s", carta[n2].valor, carta[n2].naipe);
    }
    printf("\n\n");
    system("pause");
    return 0;
}

 

*****************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this