Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Program A. Write a program that calculates how much a person would earn over

ID: 3823195 • Letter: C

Question

C++ Program

A.

Write a program that calculates how much a person would earn over a period of time if his or her salary is one penny the first day and 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 how much 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. Do not accept a number less than 1 for the number of days worked.

Using do while loop.

Explanation / Answer

#include <iostream>

using namespace std;

int main()
{
int n;
int total = 0;
cout << "Enter the number of days: ";
cin >> n;
if(n<1){
cout<<"Invalid input. Input must be greater than 0"<<endl;
}
else{
int i=0;
cout<<"Day Salary"<<endl;
do{
i++;
cout<<i<<" "<<(i * 2)<<endl;
total = total + (i * 2);
  
}while(i<=n);
cout<<"Total Pay: "<<total<<endl;
}
return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                                                                                              

sh-4.2$ main                                                                                                                                                                                                                                                           

Enter the number of days: 5                                                                                                                                                                                                                                            

Day     Salary                                                                                                                                                                                                                                                         

1       2                                                                                                                                                                                                                                                              

2       4                                                                                                                                                                                                                                                              

3       6                                                                                                                                                                                                                                                              

4       8                                                                                                                                                                                                                                                              

5       10                                                                                                                                                                                                                                                             

6       12                                                                                                                                                                                                                                                             

Total Pay: 42

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote