Question: #include #include / / For formatting output #include / / For string variable using namespace std; / / Function to read the number of pages

#include
#include // For formatting output
#include // For string variable
using namespace std;
// Function to read the number of pages for a day
int readPages(int day){
int pages;
cout << "Enter the number of pages read on Day "<< day
<<": ";
cin >> pages;
return pages;
}
// Recursive function to calculate total pages read
int calculateTotalPages(int day, int total){
if (day ==0){
return total;
}
int pages = readPages(day);
return calculateTotalPages(day -1, total + pages);
}
// Function to calculate the amount raised for a given number of pages
double calculateAmountRaised(int pages){
const double cents_per_page =5.4;
return pages * cents_per_page /100.0; // Convert cents to dollars
}
int main(){
// Get user's full name
string fullName;
cout << "Enter your full name: ";
getline(cin, fullName);
// Initialize variables
int totalDays =14;
int totalPages = calculateTotalPages(totalDays,0);
// Calculate total amount raised
double totalAmount = calculateAmountRaised(totalPages);
// Calculate averages
double dailyAverage = static_cast(totalPages)/ totalDays;
double weeklyAverage =(totalPages)/2;
// Format output
cout <<"
Summary for "<< fullName <<":
";
cout << "Total pages read: "<< totalPages <<" pages
";
cout << "Total amount raised: $"<< fixed << setprecision(2)<< totalAmount <<"
";
// Check if there are any days
if (totalDays >0){
cout << "Average pages read per day: "<< dailyAverage <<" pages
";
cout << "Average amount raised per day: $"<< dailyAverage *5.4/100.0<<"
";
cout << "Average pages read per week: "<< weeklyAverage <<" pages
";
cout << "Average amount raised per week: $"<< weeklyAverage *5.4/100.0<<"
";
}
else {
cout <<"No days recorded.
";
}
return 0;
}
I wrote this code but it is counting from 14 down, i need to start counting from day 1 to 14, could you please help?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!