From 9744b306cebb53d2abe94ed374054226266ef39c Mon Sep 17 00:00:00 2001 From: SinusFox Date: Wed, 10 May 2023 10:28:11 +0200 Subject: [PATCH 1/2] exercise 4 --- .../Simple_Calculation_extended.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 4_Simple_Calculation_extended/Simple_Calculation_extended.c diff --git a/4_Simple_Calculation_extended/Simple_Calculation_extended.c b/4_Simple_Calculation_extended/Simple_Calculation_extended.c new file mode 100644 index 0000000..f9a7265 --- /dev/null +++ b/4_Simple_Calculation_extended/Simple_Calculation_extended.c @@ -0,0 +1,33 @@ +/* Extended means using doubles in this case, so floating point numbers can be used. Thus, +the modulo operation is not usable anymore and has been removed. */ + +#include + +int main() { + // creating variables + double first = 0, second = 0, addition = 0, subtraction = 0, multiplication = 0, division = 0; + + // receiving numbers from user + printf("Please type in the first integer: "); + scanf("%lf", &first); + printf("Please type in the second integer: "); + scanf("%lf", &second); + + // checking numbers + printf("Your input: %lf and %lf\nCalculating...\n\n", first, second); + + // calculating + addition = first + second; + subtraction = first - second; + multiplication = first * second; + if (second != 0) { + division = first / second; + } else { + printf("\nError: Dividing by 0 is not allowed. Output will be 0 for devision and modulo.\n\n"); + } + + // output of calculation + printf("The results are:\n+ = %lf\n- = %lf\n* = %lf\n/ = %f\n", addition, subtraction, multiplication, division); + + return 0; +} From c06531f315529b799a5327f26d6c44bdde5b3cb8 Mon Sep 17 00:00:00 2001 From: SinusFox Date: Wed, 10 May 2023 11:26:57 +0200 Subject: [PATCH 2/2] exercise 5 --- 5_Currency_Calculator/Currency_Calculator.c | 46 +++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 5_Currency_Calculator/Currency_Calculator.c diff --git a/5_Currency_Calculator/Currency_Calculator.c b/5_Currency_Calculator/Currency_Calculator.c new file mode 100644 index 0000000..24ab015 --- /dev/null +++ b/5_Currency_Calculator/Currency_Calculator.c @@ -0,0 +1,46 @@ +#include + +int main() { + // variables + double amount = 0, usd = 1.09643, jpy = 148.33512; // eur = 1 as base currency + char currentCurrency = 0, targetCurrency; + + // input + printf("1 EUR\n2 USD\n3 JPY\n\nPlease type in the current currency: "); + scanf("%i", ¤tCurrency); + printf("Please type in the amount: "); + scanf("%lf", &amount); + printf("\n1 EUR\n2 USD\n3 JPY\n\nPlease type in the target currency: "); + scanf("%i", &targetCurrency); + + // calculating + if (currentCurrency != targetCurrency) { + // converting to base currency + switch (currentCurrency) { + case 2: + amount /= usd; + break; + case 3: + amount /= jpy; + break; + default: + break; + } + // converting to target currency + switch (targetCurrency) + { + case 2: + amount *= usd; + break; + case 3: + amount *= jpy; + default: + break; + } + } + + // output + printf("Amount in target currency is: %lf", amount); + + return 0; +}