diff --git a/03/expliztesCasting.c b/03/expliztesCasting.c index 18acb19..16dbb38 100644 --- a/03/expliztesCasting.c +++ b/03/expliztesCasting.c @@ -14,9 +14,24 @@ ********************************************************************************************/ #include +#include "../io/myio.h" + int main() { + double price = 0; + unsigned int priceEuro = 0; + unsigned int priceCents = 0; + + do + { + price = getDoubleNumber("Geben Sie einen Preis ein: "); + } while (price < 0); + + priceEuro = (unsigned int)price; + priceCents = (unsigned int)((price - priceEuro)*100); + + printf("Preis: %d Euros, %d Cents\n", priceEuro, priceCents); return 0; } \ No newline at end of file diff --git a/io/myio.c b/io/myio.c index be62239..7e7f2fe 100644 --- a/io/myio.c +++ b/io/myio.c @@ -23,5 +23,20 @@ int getNumber(const char *text) while(getchar() != '\n') {} } while(!wasSuccessful); + return number; +} + +double getDoubleNumber(const char *text) +{ + double number = 0; + int wasSuccessful = 0; + + do + { + printf("%s", text); + wasSuccessful = scanf("%lf", &number); + while(getchar() != '\n') {} + } while(!wasSuccessful); + return number; } \ No newline at end of file diff --git a/io/myio.h b/io/myio.h index ddc86ae..bb7dc15 100644 --- a/io/myio.h +++ b/io/myio.h @@ -3,5 +3,6 @@ unsigned char getSingleChar(); int getNumber(const char *text); +double getDoubleNumber(const char *text); #endif \ No newline at end of file