From 38a17714e4a180ef5f3301cc11d58f7349cd38dd Mon Sep 17 00:00:00 2001 From: juan Date: Tue, 12 Oct 2021 19:23:17 +0800 Subject: [PATCH] add discount --- pset3/5-discount.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 pset3/5-discount.c diff --git a/pset3/5-discount.c b/pset3/5-discount.c new file mode 100644 index 0000000..84d6c85 --- /dev/null +++ b/pset3/5-discount.c @@ -0,0 +1,39 @@ +#include + +// Function prototype +void calculate(int i); + +int main(void) { + // Initialize variables + int t; // Lines of input + int amount; // Amount of goods + int sum; // Sum of goods + int temp; // Temporary variable to store single price + + scanf("%d", &t); + + for (int i = 0; i < t; i++) { + sum = 0; // Sum should equal to 0 in each iteration + scanf("%d", &amount); + for (int j = 0; j < amount; j++) { + scanf("%d", &temp); + sum += temp; + } + calculate(sum); + } + + return 0; +} + +void calculate(int i) { // if cases and print discounted answer + if (i >= 400) + printf("%d\n", i - 160); + else if (i >= 300) + printf("%d\n", i - 110); + else if (i >= 200) + printf("%d\n", i - 70); + else if (i >= 100) + printf("%d\n", i - 30); + else + printf("%d\n", i); +}