Add solution for explizitesCasting.
This commit is contained in:
parent
114a412778
commit
1a1837c7fb
@ -14,9 +14,24 @@
|
|||||||
********************************************************************************************/
|
********************************************************************************************/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "../io/myio.h"
|
||||||
|
|
||||||
|
|
||||||
int main()
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
15
io/myio.c
15
io/myio.c
@ -23,5 +23,20 @@ int getNumber(const char *text)
|
|||||||
while(getchar() != '\n') {}
|
while(getchar() != '\n') {}
|
||||||
} while(!wasSuccessful);
|
} 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;
|
return number;
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user