Assuming the level of the Earth\'s oceans continues rising at about 3.1 millimet
ID: 3695226 • Letter: A
Question
Assuming the level of the Earth's oceans continues rising at about 3.1 millimeters per year, write a program that displays a table showing the total number of millimeters the oceans will have risen each year for the next 25 years Write a program that calculates how much a person earns in a month if the salary is one penny the first day, two pennies the second day, four pennies the third day, and so on with the daily pay doubling each day the employee works. The program should ask the user for the number of days the employee worked during the month and should display a table showing how much the salary was for each day worked, as well as the total pay earned for the month. The output should be displayed in dollars with two decimal points, not in pennies. Input Validation: Do not accept a number less than 1 or more than 31 for the number of days worked.Explanation / Answer
4.1).
#include<iostream>
using namespace std;
int main(){
double rising_per_year = 3.1;
for(int i=1; i<=25; i++){
cout<<"Rising level after "<<i<<" year: "<<rising_per_year<<endl;
rising_per_year += 3.1;
}
return 0;
}
/*
Output:
Rising level after 1 year: 3.1
Rising level after 2 year: 6.2
Rising level after 3 year: 9.3
Rising level after 4 year: 12.4
Rising level after 5 year: 15.5
Rising level after 6 year: 18.6
Rising level after 7 year: 21.7
Rising level after 8 year: 24.8
Rising level after 9 year: 27.9
Rising level after 10 year: 31
Rising level after 11 year: 34.1
Rising level after 12 year: 37.2
Rising level after 13 year: 40.3
Rising level after 14 year: 43.4
Rising level after 15 year: 46.5
Rising level after 16 year: 49.6
Rising level after 17 year: 52.7
Rising level after 18 year: 55.8
Rising level after 19 year: 58.9
Rising level after 20 year: 62
Rising level after 21 year: 65.1
Rising level after 22 year: 68.2
Rising level after 23 year: 71.3
Rising level after 24 year: 74.4
Rising level after 25 year: 77.5
*/
4.2)
#include<iostream>
using namespace std;
int main(){
int current_pay = 1;
int numberOfDays = -1;
int total = 0;
// asking for number of days and checking validity
while(numberOfDays<1 || numberOfDays > 31){
cout<<"Enter number of days: ";
cin>>numberOfDays;
}
for(int i=1; i<=numberOfDays; i++){
cout<<"Pay for "<<i<<" day: "<<current_pay<<endl;
total = total + current_pay;
current_pay = current_pay*2;
}
cout<<endl;
cout<<"Total Pay: $"<<total/100<<endl;
return 0;
}
/*
Output:
Enter number of days: 10
Pay for 1 day: 1
Pay for 2 day: 2
Pay for 3 day: 4
Pay for 4 day: 8
Pay for 5 day: 16
Pay for 6 day: 32
Pay for 7 day: 64
Pay for 8 day: 128
Pay for 9 day: 256
Pay for 10 day: 512
Total Pay: $10
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.