Compare commits
No commits in common. "f98e5f71337a73331734d4840a9e1e08214b7cc3" and "1e42ebe41d76152f8f04585a6822c3d6e12a132f" have entirely different histories.
f98e5f7133
...
1e42ebe41d
2
.idea/Info2P5.iml
generated
2
.idea/Info2P5.iml
generated
@ -1,2 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module classpath="CIDR" type="CPP_MODULE" version="4" />
|
|
||||||
BIN
bucstrei.exe
BIN
bucstrei.exe
Binary file not shown.
68
farben.c
68
farben.c
@ -1,68 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
// Vergleich zweier Strings ohne Beachtung der Groß-/Kleinschreibung
|
|
||||||
int string_equals_ignore_case(const char *a, const char *b) {
|
|
||||||
while (*a && *b) {
|
|
||||||
if (tolower((unsigned char)*a) != tolower((unsigned char)*b)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
a++;
|
|
||||||
b++;
|
|
||||||
}
|
|
||||||
return *a == *b;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prüft, ob die Eingabe eine erlaubte Grundfarbe ist
|
|
||||||
int is_valid_color(const char *color) {
|
|
||||||
return string_equals_ignore_case(color, "Rot") ||
|
|
||||||
string_equals_ignore_case(color, "Gruen") ||
|
|
||||||
string_equals_ignore_case(color, "Violett");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gibt die Mischfarbe zurück
|
|
||||||
const char* mix_colors(const char *color1, const char *color2) {
|
|
||||||
if (string_equals_ignore_case(color1, "Rot") && string_equals_ignore_case(color2, "Rot")) {
|
|
||||||
return "Rot";
|
|
||||||
}
|
|
||||||
if ((string_equals_ignore_case(color1, "Rot") && string_equals_ignore_case(color2, "Gruen")) ||
|
|
||||||
(string_equals_ignore_case(color1, "Gruen") && string_equals_ignore_case(color2, "Rot"))) {
|
|
||||||
return "Gelb";
|
|
||||||
}
|
|
||||||
if ((string_equals_ignore_case(color1, "Rot") && string_equals_ignore_case(color2, "Violett")) ||
|
|
||||||
(string_equals_ignore_case(color1, "Violett") && string_equals_ignore_case(color2, "Rot"))) {
|
|
||||||
return "Purpur";
|
|
||||||
}
|
|
||||||
if (string_equals_ignore_case(color1, "Gruen") && string_equals_ignore_case(color2, "Gruen")) {
|
|
||||||
return "Gruen";
|
|
||||||
}
|
|
||||||
if ((string_equals_ignore_case(color1, "Gruen") && string_equals_ignore_case(color2, "Violett")) ||
|
|
||||||
(string_equals_ignore_case(color1, "Violett") && string_equals_ignore_case(color2, "Gruen"))) {
|
|
||||||
return "Blau";
|
|
||||||
}
|
|
||||||
if (string_equals_ignore_case(color1, "Violett") && string_equals_ignore_case(color2, "Violett")) {
|
|
||||||
return "Violett";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
char user_colors[2][20]; // Platz für 2 Farben
|
|
||||||
int attempts = 0;
|
|
||||||
|
|
||||||
while (attempts < 2) {
|
|
||||||
printf("Bitte gib eine Grundfarbe (Rot, Gruen oder Violett) ein: ");
|
|
||||||
scanf("%19s", user_colors[attempts]);
|
|
||||||
while (getchar() != '\n'); // Eingabepuffer leeren
|
|
||||||
|
|
||||||
if (is_valid_color(user_colors[attempts])) {
|
|
||||||
printf("Du hast %s gewaehlt.\n", user_colors[attempts]);
|
|
||||||
attempts++;
|
|
||||||
} else {
|
|
||||||
printf("Ungueltige Eingabe. Bitte versuche es erneut.\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Die Mischfarbe ist dann: %s\n", mix_colors(user_colors[0], user_colors[1]));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user