Add solution for explizitesCasting.

This commit is contained in:
paulusja 2026-04-23 13:02:21 +02:00
parent 114a412778
commit 1a1837c7fb
3 changed files with 31 additions and 0 deletions

View File

@ -14,9 +14,24 @@
********************************************************************************************/
#include <stdio.h>
#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;
}

View File

@ -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;
}

View File

@ -3,5 +3,6 @@
unsigned char getSingleChar();
int getNumber(const char *text);
double getDoubleNumber(const char *text);
#endif