Bank Charge C program, is this okay?

closed account (DLUk92yv)
So here is the question:
Suppose you transfer $N and bank's charge occurs as follows:
Cost is $10, if N ≤500
Cost is $10+2% of N, if 500 < N < 1000
Cost is $10 + 1% of N, if 1000 ≤ N ≤ 3000
Maximum cost is 40$.

For example: input=2000
output should be 33.00

Here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>
int main()
{
  float N, sum;
  N>=1 && N<=10000;
 scanf("%f", &N);

 if (N<=500) sum=10;
 else if (N>500 && N<1000)  sum=10+(2*(N-500)/100);
 else if (N>=1000 && N<=3000) sum=19.98+(1*(N-999)/100);

printf("%0.3f", sum);
 return 0;
}



There is a problem at the last part " else if (N>=1000 && N<=3000) sum=19.98+(1*(N-999)/100); " when i run the program and i give the value of 2000 the output is not 33.00. So the mistake is at calculating the sum of 2000$ but I can't figure it out exactly..can you help me?
Last edited on
N>=1 && N<=10000;
What is that line supposed to do. Hint: It doesn't do anything.

sum=10+(2*(N-500)/100);
That doesn't represent the calculation as stated in the problem statement.

sum=19.98+(1*(N-999)/100);
Ditto.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.
Hint: You can edit your previous post, highlight your code and press the <> formatting button.
closed account (DLUk92yv)
actually yeah the first line its the limit of N because if the input would be more than 10000 then it shouldnt print anything.
did you even try to give examples? because if i would do the calculations exactly as the problem required than the answer wouldn't be 33.00 for 2000$.
Your calculation is off. You should do it like this:
1
2
sum = 10+N*0.02
sum = 10+N*0.01
closed account (DLUk92yv)
okay look, try to give N=2000, is the output 33? no. so it means sum=10+N*0.01 is not correct.
actually yeah the first line its the limit of N because if the input would be more than 10000 then it shouldnt print anything.

Line 5: How does it not print anything? That is not an if statement. As I said before, that statement does nothing. The rest of the program will execute regardless of the value of N.

did you even try to give examples? because if i would do the calculations exactly as the problem required than the answer wouldn't be 33.00 for 2000$.

Line 9: You're not reading the instructions correctly. Why are you subtracting 500 from N before taking 2%? The instructions say nothing about subtracting 500 first.

Line 10: Why are you setting the fixed cost to 19.99? The instructions say for over $1000 the fixed cost is $10. And again, why are you subtracting 999 from N? The instructions say nothing about that.

Line 11: You have no code for the case where N > $3000 and less than $10000 (i.e. limit is $40).

When I do this on a calculator, I get 2000 * 1% = $20 + $10 = $30. I don't agree that the correct answer is $33.






closed account (DLUk92yv)
i don't agree either but that's the right answer according to the solution page
Topic archived. No new replies allowed.