Write a program that calculates the amount of money a person would earn over a p
ID: 3804632 • Letter: W
Question
Write a program that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should ask the user for the number of days. Display a table showing what the salary was for each day, and then show the total pay at the end of the period. The output should be displayed in a dollar amount, not the number of pennies.
Can someone please assist in showing me how to do this in "C" programming language only? Thank you.
Explanation / Answer
Answer:
def main():
# Ask the user how many days they worked.
ndays = input('Enter the number of days worked: ')
pay = 0.005 # my starting salary
# Create the function to calculate the pay per day.
for day in range(1,ndays+1):
#pay = pay * 2.0
pay *= 2.0
print ' Day', day, ' Salary', pay
# State the results of the function.
print 'Your salary on day', ndays, 'would be $%.2f' % pay
# Call the main function.
main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.