Write a program that asks a user for their birth year encoded as two digits (like "62") and
for the current year, also encoded as two digits (like "99"). The program is to correctly
write out the users age in years.
Year of Birth:
62
Current year:
99
Your age: 37
During a special sale at a store, a 10% discount is taken on purchases over $10.00. Write
a program that asks for the amount of purchases, then calculates the discounted price. The
purchase amount will be input in cents (as an integer):
Enter amount of purchases:
2000
Discounted price: 1800
Use integer arithmetic throughout the program.
======================================================
Sam and Ella's Delicatessen wants you to write a program to take orders from the
Internet. Your program asks for the item, its price, and if overnight shipping is wanted.
Regular shipping for items under $10 is $2.00; for items $10 or more shipping is $3.00.
For overnight delivery add $5.00.
Enter the item:
Tuna Salad
Enter the price:
450
Overnight delivery (0==no, 1==yes)
1
Invoice:
Tuna Salad 4.50
shipping 7.00
total 11.50
(Use our ordinary IO methods. A real Internet order form would use different I/O methods, but ignore this.)
Write a program that computes the following sum:
sum = 1.0/1 + 1.0/2 + 1.0/3 + 1.0/4 + 1.0/5 + .... + 1.0/N
N will be an integer limit that the user enters.
Enter N
4
Sum is: 2.08333333333
=================================================
Write a program that adds up the squares and adds up the cubes of integers from 1 to N,
where N is entered by the user:
Upper Limit:
5
The sum of Squares is 55
The sum of Cubes is 225
Do this by using just one loop that generates the integers. Of course, if you really needed
to calculate these sums you would use the appropriate formulas:
12 + 22 + 32 + ... + n2 = n(n+1)(2n+1)/6
13 + 23 + 33 + ... + n3 = n2(n+1)2/4
Add these formulas to your program and print out their results as well as that of the
explicit summations
A mail order company charges $3.00 for handling, free shipping for orders 10 pounds or
less, plus $0.25 for each pound over 10. Write a program that repeatedly asks the user for
the weight of an order, then writes out the shipping charge. The program stops when a
weight of zero or less is entered.
Weight of Order:
5
Shipping Cost: $3.00
Weight of Order
20
Shipping Cost: $5.50
Weight of Order
0
bye