4.2-4.5

Ace your homework & exams now with Quizwiz!

Write an if/else statement that compares the variable age with 65, adds 1 to the variable seniorCitizens if age is greater than or equal to 65, and adds 1 to the variable nonSeniors otherwise.

if (age >=65) seniorCitizens++; elsenonSeniors++;

Assume that the variables gpa, deansList and studentName, have been declared and initialized . Write a statement that both adds 1 to deansList and prints studentName to standard out if gpa exceeds 3.5.

if (gpa > 3.5) { deansList++; cout << studentName; }

Assume that isIsosceles is a bool variable , and that the variables isoCount, triangleCount, and polygonCount have all been declared and initialized . Write a statement that adds 1 to each of these count variables (isoCount, triangleCount, and polygonCount) if isIsosceles is true .

if (isIsosceles==true) { isoCount++; triangleCount++; polygonCount++; }

Write a conditional that decreases the variable shelfLife by 4 if the variable outsideTemperature is greater than 90.

if (outsideTemperature > 90) shelfLife -= 4;

Write an if/else statement that compares the value of the variables soldYesterday and soldToday, and based upon that comparison assigns salesTrend the value -1 or 1.-1 represents the case where soldYesterday is greater than soldToday; 1 represents the case where soldYesterday is not greater than soldToday.

if (soldYesterday>soldToday) salesTrend=-1; else salesTrend=1;

Write a conditional that assigns 10,000 to the variable bonus if the value of the variable goodsSold is greater than 500,000.

if(goodsSold > 500000) bonus = 10000;

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.

if(nbooksPurchased > 4){ if(isPremiumCustomer){ freeBooks = 1; if(nbooksPurchased > 7){ freeBooks = 2; } }else{ freeBooks = 0; if(nbooksPurchased > 6){ freeBooks = 1; } if(nbooksPurchased > 11){ freeBooks = 2; } } }else{freeBooks = 0;}


Related study sets

Advanced JavaScript - Technical Interview

View Set

MKT 3360 - Exam 1 practice questions

View Set

Collaborative-Health Promotion and Maintenance

View Set

Saunders Psychiatric Medications

View Set

Type of Insurance Policies (xcel solutions)

View Set

Molecular Symmetry and Molecular Orbital Theory

View Set

Toddler NCLEX, Toddler, Preschool-passp

View Set