我做了一个小骰子游戏,如果我投掷相同数字的5倍,我应该获得大牌;如果我投掷相同数字的4倍,我应该获得扑克牌。
我的问题是,如果我尝试用4赢得一个扑克,那么我的代码只能使用“ 1”和“ 2”算不上
#include <stdio.h>
void abfrage(int wurf[], int size){
int i;
for (i=0; i<size; i++){
printf("Würfel %i: ", i+1);
scanf("%i", &wurf[i]);
}
}
// switch int*
void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}
// Sort the array
void bubbleSort(int wurf[], int size)
{
int i, j;
for (i = 0; i < size-1; i++){
for (j = 0; j < size-i-1; j++){
if (wurf[j] > wurf[j+1])
{
swap(&wurf[j], &wurf[j+1]);
}
}
}
}
void arrayausgabe(int wurf[], int size){
int u = 0;
for (u=0;u<size;u++) {
printf("array nummer %i: ", u); // err with "&"
printf("%i \n", wurf[u]);
}
}
void bewertung(int wurf[]){
int *x;
x = wurf;
if (*x==*(x+1)==*(x+2)==*(x+3)==*(x+4)) {
printf("Grand");
}else if (*x==*(x+1)==*(x+2)==*(x+3) || *(x+1)==*(x+2)==*(x+3)==*(x+4)) {
printf("Poker");
}else if ((*x==*(x+1)==*(x+2) && *(x+3)==*(x+4) )||(*(x+2)==*(x+3)==*(x+4) && *x==*(x+1))) {
printf("Full House");
}else {
printf("HAAA Verloren");
}
}
int main() {
int wurf[5];
printf("Programm Würfelspiel\nGrand\tgleiche Augenzahl auf allen 5 Würfeln\nPoker\tgleiche Augenzahl auf 4 Würfeln\nFull House\tgleiche und 2 gleiche Augenzahlen\n\nBitte gibt deine gewürfelten zahlen ein\n");
abfrage(wurf, 5);
bubbleSort(wurf, 5);
arrayausgabe(wurf, 5);
bewertung(wurf);
}
我正大一,所以如果代码看起来有点乱,很抱歉