In: Computer Science
An employee applied for a job in a company and agreed to be paid as follows: He will recieve P1 on the 1st day, P2 on the 2nd day, P4 on the 3rd day, P8 on the 4th, and so on. ( meaning his daily pay doubles each day)> How much will he recieve the at the end of 30 days?
use for loop or looping
Thanks for the question, here is a simple program in C++ that calculates the pay the person will receive on 30th day. We are assuming the person starts with $1 on the first day.
Using for loop we have evaluated his 30th pay. Here is the screenshot of the out.
======================================================================================
#include<iostream>
using namespace std;
int main(){
int pay=1;
cout<<"Day - "<<1<<" - Pay Amount:
$"<<pay<<endl;
for(int day=2; day<=30; day++){
pay = 2*pay; // double the salary of the
previous day for the current day
cout<<"Day - "<<day<<" - Pay
Amount: $"<<pay<<endl;
}
}