add discount
This commit is contained in:
parent
8e1bb153e4
commit
38a17714e4
39
pset3/5-discount.c
Normal file
39
pset3/5-discount.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
#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);
|
||||
}
|
Loading…
Reference in a new issue