What would be the value of discountRate after the following

What would be the value of discountRate after the following statements are executed?

double discountRate = 0.0;

int purchase = 1250;

if (purchase > 1000)

                discountRate = .05;

if (purchase > 750)

                discountRate = .03;

if (purchase < 2500)

                discountRate = .01;

else

                discountRate = 0;

.05

.03

.01

0

.05

.03

.01

0

Solution

int purchase = 1250;
Now the condition is satisfied, so the if condition is executed. discountRate becomes .05
if (purchase > 1000)
discountRate = .05;

Even here the condition is satisfied, so the if condition is executed. discountRate becomes .03
if (purchase > 750)
discountRate = .03;

Again the condition is satisfied, so the if condition is executed. discountRate becomes .01
if (purchase < 2500)
discountRate = .01;
else
discountRate = 0;

So the final value of discountRate is .01

What would be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 1250; if (purchase > 1000) dis

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site