halo
This commit is contained in:
parent
37ce336e00
commit
f98e5f7133
68
farben.c
Normal file
68
farben.c
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#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