Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Online Book Merchants offers premium customers 1 free book with every purchase o

ID: 3639415 • Letter: O

Question

Online Book Merchants offers premium customers 1 free book with every purchase of 5 or more books and offers 2 free books with every purchase of 8 or more books. It offers regular customers 1 free book with every purchase of 7 or more books, and offers 2 free books with every purchase of 12 or more books.

Write a statement that assigns freeBooks the appropriate value based on the values of the bool variable isPremiumCustomer and the int variable nbooksPurchased .


I tried
if (isPremiumCustomer==true)
{
if (nbooksPurchased >= 5)
{
freeBooks==1;
{
if (nbooksPurchased >= 8)
{
freeBooks==2;
}
}
}
}
else if (isPremiumCustomer==false)
{
if (nbooksPurchased >= 7)
{
freeBooks==1;
{
if (nbooksPurchased >= 12)
{
freeBooks==2;
}
}
}
}

but the system said:
Remarks:
     ?     At Execution

Problems Detected:
     ?     The value of freeBooks is incorrect.
     ?     You did not assign a value to freeBooks

and this one ......


Write a loop that reads strings from standard input where the string is either "duck" or "goose". The loop terminates when "goose" is read in. After the loop, your code should print out the number of "duck" strings that were read.

Explanation / Answer

Your code has following errors (underlined and bold) :

if (isPremiumCustomer==true)
{
if (nbooksPurchased >= 5)
{
freeBooks==1;

/* You do not use == when assigning values. It is only used for comparison.

Hence this line compares the value of freeBooks to 1. But since freeBooks has not been assigned any value therefore error occurs.

Instead you should write freeBooks = 1; */

{
if (nbooksPurchased >= 8)
{
freeBooks==2;
}
}
}
}
else if (isPremiumCustomer==false)
{
if (nbooksPurchased >= 7)
{
freeBooks==1;
{
if (nbooksPurchased >= 12)
{
freeBooks==2;
}
}
}
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

2)

int count = 0;

char str[10];

scanf("%s",str);

while(strcmp(str,"goose"))

{

if(!strcmp(str,"duck"))

count ++;

scanf("%s",str);

}