BUPT-homework/pset3/5-discount.c

40 lines
800 B
C
Raw Normal View History

2021-10-12 19:23:17 +08:00
#include <stdio.h>
// 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);
}