Chapter 3.3 - When You Mix Apples and Oranges: Type Conversion C++

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Assuming the item is paid for with a minimum amount of change and just single dollars, write an expression for the amount of change (in cents) that would have to be paid.

price % 100

Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Assuming the item is paid for with a minimum amount of change and just single dollars, write an expression for the number of single dollars that would have to be paid.

price / 100

Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Write a statement that prints the value of price in the form "X dollars and Y cents". So, if the value of price was 4321, your code would print "43 dollars and 21 cents". If the value was 501 it would print "5 dollars and 1 cents". If the value was 99 your code would print "0 dollars and 99 cents".

cout << price/100 << " dollars and " << price%100 << " cents" << endl;

In mathematics, the Nth harmonic number is defined to be 1 + 1/2 + 1/3 + 1/4 + ... + 1/N. So, the first harmonic number is 1, the second is 1.5, the third is 1.83333... and so on. Write an expression whose value is the 8th harmonic number.

(1.0 + 1.0/2.0 + 1.0/3.0 + 1.0/4.0 + 1.0/5.0 + 1.0/6.0 + 1.0/7.0 + 1.0/8.0)

In mathematics, the Nth harmonic number is defined to be 1 + 1/2 + 1/3 + 1/4 + ... + 1/N. So, the first harmonic number is 1, the second is 1.5, the third is 1.83333... and so on. Assume that n is an integer variable whose value is some positive integer N. Assume also that hn is a double variable whose value is the Nth harmonic number. Write an expression whose value is the (N+1)th harmonic number.

hn + 1.0/(n+1)

In mathematics, the Nth harmonic number is defined to be 1 + 1/2 + 1/3 + 1/4 + ... + 1/N. So, the first harmonic number is 1, the second is 1.5, the third is 1.83333... and so on. Assume that n is an integer variable whose value is some integer N greater than 1. Assume also that hn is a double variable whose value is the Nth harmonic number. Write an expression whose value is the (N-1)th harmonic number.

hn - 1.0 /(n)


Kaugnay na mga set ng pag-aaral

Prep U: Ch. 2; Health History and Interview

View Set

Chapter 10: Public Speaking: Beginning and Ending the Speech

View Set

JOUR 225 Bonebright Exam 3 Chapters 4-6, 9, 10

View Set

MasteringBiology Chapter 6: A Tour of the Cell

View Set

A&PII CH 14 Brain & Cranial Nerves HW/Study Quiz

View Set

Module 4- Caring and Communication

View Set

(Psych) Survivors of abuse and neglect, testbankgo

View Set