Help with C Vectors

Asked

Viewed 39 times

0

Staff helps me out on a C.

I have a lottery question.

My lottery looks like this: 5 numbers from 1 to 60 and 1 number (sixth) from 1 to 4.

I generated an X vector to generate 5 random numbers between 1 and 60 and another Y vector to generate 1 random number between 1 and 4.

ai he stored the two vectors (6 numbers) in . txt

In the program below u am reading this file and after reading the file it printa on the screen, and then the program asks me the official results of the draw, the 5 numbers I store in the vector result and the sixth number I store in the vector cash, after that the program is to display the official result I just typed and say how many numbers I hit.

But there is one, first: When I type in the official result the sixth number that stores in the vector it prints the number 8 independent of what I typed and the second problem is that I can’t add up how many I hit.

Help me please!

#include<stdio.h>
#include<locale.h>
#include<time.h>
#include<stdlib.h>
#include<conio.h>
main()
{  int i,x[5],y[1],resultado[5],cash[1],pontos=0,j,k;
   FILE *arquivo;
   setlocale(LC_ALL,"Portuguese");
   if((arquivo=fopen("cash4life.txt","r"))==NULL) 
    printf("Erro na leitura do arquivo!\n");
     else
     { for(i=0;i<5;i++)  
       fscanf(arquivo,"%5d",&x[i]);
       for(k=0;k<1;k++)
       fscanf(arquivo,"%d",&y[k]);
     }
   printf("Este programa verifica quantos pontos foram feito no Clasico Loto do Chile.\n");
   printf("O arquivo jogo.txt tem o seguinte jogo armazenado\n");
   
   printf("\nVetor armazenado\n"); 
   printf("Números principais:");
   for(i=0;i<5;i++)
    printf("%3d ",x[i]);
    printf("\n\n");
    printf("Cash Ball:");
    for(k=0;k<1;k++)
    printf("%2d",y[k]);
    
   printf("\nDigite o resultado oficial do Clasico Loto do Chile\n"); 
   for(i=0;i<5;i++)
    scanf("%d",&resultado[i]);
   for(k=0;k<1;k++)
   printf("Digite o número do cash ball:");
   scanf("%2d",&cash[k]);
   
   printf("\nO resultado oficial do Clasico Loto do Chile foi:\n");
   printf("Números principais:");
   for(i=0;i<5;i++)
    printf("%6d",resultado[i]);
    printf("\n\n");
    printf("Cash Ball:");
    for(k=0;k<1;k++)
    printf(" %2d",cash[k]);
    
   for(i=0;i<5;i++)
    for(j=0;j<5;j++)
     for(k=0;k<1;k++)
      if(x[i]==resultado[j])
       pontos=pontos+1;
   printf("\n\n Você acertou %d pontos\n",pontos); 
   printf("\nFim.\n");
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.