92.9k views
0 votes
What would be the value of discountRate after the following statements are executed?

double discountRate = 0.0;
int purchase = 1250;
char cust = 'N';
if (purchase > 1000)
if (cust == 'Y')
discountRate = .05;
else
discountRate = .04;
else if (purchase > 750)
if (cust == 'Y')
discountRate = .04;
else
discountRate = .03;
else
discountRate = 0;

a) .04

b) .03

c) .05

d) 0

User Nesh
by
4.3k points

1 Answer

4 votes

Answer:

a) .04

Step-by-step explanation:

We have purchase =1250,discountRate=0.0 and cust='N'.First if statement will be checked since our purchase is greater than 1000 this if statement will be executed.Then cust will be checked since our cust is not Y so else will be executed so the discountRate will become 0.04.Any other elseif or else will not be executed.

User BZezzz
by
5.2k points