Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. int main()
  7. {
  8. int anz_spieler;
  9. int spielernummer[4];
  10.  
  11.  
  12. int i, max, min,location =1;
  13. int abstand[4];
  14.  
  15.  
  16. int punkte[4];
  17. punkte[1]=0;
  18. punkte[2]=0;
  19. int ende;
  20. ende = 1;
  21. printf("--Willkommen zum Ratespiel--\n");
  22. printf("Wie viele Spieler (1-4)\n");
  23. scanf("%d", &anz_spieler);
  24. do{
  25. abstand[0] = 100;
  26. if(anz_spieler>1){
  27. for(int i = 1;i <= anz_spieler;i++){
  28.  
  29. printf("Zahl von Spieler %d : ",i);
  30. scanf("%d", &spielernummer[i]);
  31. }
  32.  
  33. srand(time(NULL));
  34. int randomya = random()%100;
  35. printf("Gezogen wurde %d \n",randomya);
  36.  
  37.  
  38. for(int j = 1; j<=anz_spieler;j++){
  39. if(randomya >spielernummer[j]){
  40. abstand[j] = randomya - spielernummer[j];
  41. }
  42. if(randomya < spielernummer[j]){
  43. abstand[j] = spielernummer[j] - randomya;
  44. }
  45. }
  46.  
  47. /* Assume first element as maximum and minimum */
  48. min = abstand[0];
  49.  
  50. /*
  51. * Find maximum and minimum in all array elements.
  52. */
  53. for(i=1; i<=anz_spieler; i++)
  54. {
  55.  
  56. /* If current element is smaller than min */
  57. if(abstand[i] < min)
  58. {
  59. min = abstand[i];
  60. location = i;
  61. }
  62. }
  63.  
  64. printf("Gewinner ist Spieler %d mit einem Abstand von %d \n \n", location, min);
  65. punkte[location]++;
  66.  
  67. printf("Spielstand \n");
  68. for(int i = 1;i <= anz_spieler;i++){
  69. printf("Spieler %d : %d \n",i, punkte[i]);
  70. }
  71.  
  72. printf("Neues Spiel (1)/ Spiel beenden (2)?");
  73. scanf("%d", &ende);
  74. }
  75. if(anz_spieler==1){
  76. srand(time(NULL));
  77. int randomzahl = random()%100;
  78. printf("Zahl von Spieler 1 : ");
  79. scanf("%d", &spielernummer[1]);
  80.  
  81.  
  82. printf("\n Spieler 2 (KI) wählt %d \n",randomzahl);
  83.  
  84. srand(time(NULL));
  85. int randomya = random()%100;
  86. printf("Gezogen wurde %d \n",randomya);
  87.  
  88. spielernummer[2]=randomzahl;
  89.  
  90. for(int j = 1; j<=anz_spieler+1;j++){
  91. if(randomya >spielernummer[j]){
  92. abstand[j] = randomya - spielernummer[j];
  93. }
  94. if(randomya < spielernummer[j]){
  95. abstand[j] = spielernummer[j] - randomya;
  96. }
  97. }
  98.  
  99. min = abstand[0];
  100.  
  101. /*
  102. * Find maximum and minimum in all array elements.
  103. */
  104. for(i=1; i<=anz_spieler+1; i++)
  105. {
  106.  
  107. /* If current element is smaller than min */
  108. if(abstand[i] < min)
  109. {
  110. min = abstand[i];
  111. location = i;
  112. }
  113. }
  114.  
  115. printf("Gewinner ist Spieler %d mit einem Abstand von %d \n \n", location, min);
  116. punkte[location]++;
  117.  
  118. printf("Spielstand \n");
  119. for(int i = 1;i <= anz_spieler+1;i++){
  120. printf("Spieler %d : %d \n",i, punkte[i]);
  121. }
  122.  
  123. printf("Neues Spiel (1)/ Spiel beenden (2)?");
  124. scanf("%d", &ende);
  125.  
  126.  
  127.  
  128. }
  129.  
  130. }while(ende==1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement