In: Computer Science
Design a c++ program that calculates the amount of money a person would earn over a period of time if his salary is one penny the first day, two pennies 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 total pay at the end of the period. the output should be displayed in a dollar amount, not the number of pennies. The program must include at least one function in addition to the main function and must use the loop as well.
The c++ code for your assignment is given below. If you have any question let me know in comments.
******************************salary.cpp**********************************
#include <iostream>
#include<cmath>
using namespace std;
long total_money(int days){
long total=0;
cout<<"salary Table"<<endl;
cout<<"Day\t\tSalary"<<endl;
for(int i=0;i<days;i++){
total=total+pow(2,i);
cout<<"Day
"<<i+1<<"\t\t"<<pow(2,i)<<endl;
}
return total;
}
int main()
{
long total=0;
double dollars;
int days;
cout<<"Enter the number of days:";
cin>>days;
total=total_money(days);
dollars=(double)total/100;
cout<<"Total money earned is:
"<<dollars<<"$"<<endl;
return 0;
}