Last active
June 4, 2018 15:03
-
-
Save horstjens/1773dc1d3becc61c8122 to your computer and use it in GitHub Desktop.
zahlenschloss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<stdlib.h> | |
#include<time.h> | |
int z = 0; | |
int level; | |
/* int gen(); | |
int spiel(); */ | |
struct array{ int wert[3]; }; | |
struct array random_array(void) { | |
int i; | |
struct array z; | |
for(i = 0; i < sizeof(struct array) / sizeof(int); i++) { | |
z.wert[i] = gen(); | |
} | |
return z; | |
} | |
struct array ask_array(void) { | |
int i; | |
struct array z; | |
for(i = 0; i < sizeof(struct array) / sizeof(int); i++) { | |
printf("Wert %d eingeben: ",i); | |
scanf("%d",&z.wert[i]); | |
} | |
return z; | |
} | |
void output_array(struct array z) { | |
int i; | |
int quersumme = 0; | |
/* printf("Quersumme vorher: %d\n", quersumme); */ | |
for(i = 0; i < sizeof(struct array) / sizeof(int); i++) { | |
printf("%d\t", z.wert[i]); | |
quersumme += z.wert[i]; | |
} | |
printf("\n"); | |
printf("Quersumme: %d\n", quersumme); | |
} | |
int gen(void) | |
{ | |
int zahl; | |
zahl = rand()%10; | |
return zahl; | |
} | |
void main(void) | |
{ | |
int i, ein[3]; | |
int abbruch = 0; | |
struct array new_array; | |
srand(time(NULL)); // deshalb brauchen wir TIME | |
while(1 == 1){ | |
printf("derzeitiger Wert von Array:\n"); | |
output_array(new_array); | |
printf("Zahlenschloss\n\n"); | |
printf("Menue\n"); | |
printf("1\tSpiel starten mit Zufallszahl\n2\tSpiel starten mit eigenen Zahlen\n3\tSchwierigkeitsgrad festlegen\n4\tEnde\n"); | |
scanf("%d",&i); | |
getchar(); | |
printf("Die Eingabe war: %d\n",i); | |
switch (i) | |
{ | |
case 1: | |
/* spiel(gen(),gen(),gen()); */ | |
new_array = random_array(); | |
abbruch = 0; | |
break; | |
case 2: | |
abbruch = 0; | |
printf("Zahl manuell eingeben.\n"); | |
new_array = ask_array(); | |
printf("Danke fuer die Eingabe."); | |
break; | |
case 3: printf("Geben Sie die Anzahl der Stellen an\n"); | |
printf("\t(2 bis 6)\n"); | |
scanf("%i",&level); | |
getchar(); | |
break; | |
case 4: | |
printf("Ende\n"); | |
abbruch = 1; | |
break; | |
default: | |
printf("Fehlerhafte Eingabe\n"); | |
} | |
if (abbruch == 1) break; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
int gen(); | |
int init(); | |
int spiel(); | |
int level = 3; | |
void main() | |
{ | |
int *p1, *p2, *p3, quer; | |
int z = 3; | |
int i, schlosszahl[z]; | |
int abbruch = 0; | |
srand(time(NULL)); | |
schlosszahl[0] = gen(); | |
schlosszahl[1] = gen(); | |
schlosszahl[2] = gen(); | |
p1 = &schlosszahl[0]; | |
p2 = &schlosszahl[1]; | |
p3 = &schlosszahl[2]; | |
while(1 == 1){ | |
printf("Zahlenschloss\n\n"); | |
printf("Menue\n"); | |
printf("1\tSpiel starten\n2\tNeue Zahl generieren\n3\tSchwierigkeitsgrad festlegen\n4\tEnde\n"); | |
printf("\nschlosszahl ist:%d%d%d\n",schlosszahl[0], schlosszahl[1], schlosszahl[2]); | |
quer = *p1 + *p2 + *p3; | |
printf("Quersumme ist:%d\n",quer); | |
printf("bitte waehle einen Menuepunkt:\n"); | |
scanf("%d",&i); | |
getchar(); | |
printf("Die Eingabe war: %d\n",i); | |
switch (i) | |
{ | |
case 1: spiel(*p1, *p2, *p3, quer, z); | |
abbruch = 0; | |
break; | |
case 2: | |
schlosszahl[0] = gen(); | |
schlosszahl[1] = gen(); | |
schlosszahl[2] = gen(); | |
abbruch = 0; | |
break; | |
case 3: printf("Geben Sie die Anzahl der Stellen an\n"); | |
printf("\t(2 bis 6)\n"); | |
scanf("%i",&level); | |
getchar(); | |
break; | |
case 4: | |
printf("Ende\n"); | |
abbruch = 1; | |
break; | |
default: | |
printf("Fehlerhafte Eingabe1\n"); | |
} | |
if (abbruch == 1) break; | |
} | |
} | |
int gen(void){ | |
int zahl; | |
zahl = rand()%10; | |
return zahl; | |
} | |
int spiel(int *p1, int *p2, int *p3, int quer, int z){ | |
int schlosszahl, richtig; | |
int a, b, c, d, e, f; | |
do { | |
printf("Geben sie eine %d-Stellige Zahl ein.\n",z); | |
scanf("%d",&schlosszahl); | |
int getchar(); | |
switch(z){ | |
case 2: | |
break; | |
case 3: | |
if (schlosszahl <= 99 || schlosszahl >= 1000) { | |
printf("Fehlerhafte Eingabe!2\n"); | |
break; | |
} | |
a = (schlosszahl / 100); // erste Stelle | |
/* schlosszahl = (schlosszahl -a*100); | |
b = (schlosszahl /10); | |
schlosszahl = (schlosszahl - b*10); */ | |
b = (schlosszahl - (a*100)) / 10; | |
c = schlosszahl - (a*100) - (b* 10); | |
printf("Schlosszahl = %d %d %d\n", a, b, c); | |
richtig = 0; | |
/* printf("klaus seine pointer kommen bald. p1 is derzeit %d\n",p1);*/ | |
if (a == p1) ++richtig; | |
if (b == p2) ++richtig; | |
if (c == p3) ++richtig; | |
/* printf("Fehler in der Auswertung\n"); */ | |
printf("%d Zahlen sind richtig\n",richtig); | |
break; | |
case 4: | |
break; | |
case 5: | |
break; | |
case 6: | |
break; | |
default: printf("level seltsam. Da stimmt was nicht!"); | |
} | |
} while (richtig != z); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment