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

C++ Hi, Please, Do not use using namespace std; Please write a detailed comment

ID: 3596090 • Letter: C

Question

C++

Hi,

Please, Do not use using namespace std;

Please write a detailed comment so I can understand the code and will be able to solve a problem like that.

Many Thanks!

Write a program to calculate the sum of a $.01 a day, doubled for n number of days. For example, on the first day you would receive $.01, the second you would receive $.02 for a total of $.03. The third day you would receive $.04 for a total of S.07. Get the input for the number of days from the user, but make sure it is between 1 and 30 days. Display the number of cents accumulated along with the number of days entered by the user.

Explanation / Answer

#include<iostream>
int main(){
int n,i;
//initial sum is zero
float sum = 0;
std::cout << "Enter number of days:";
std::cin>> n;
//calculate sum for n days
for(i=1;i<n+1;i++){
//add 0.01 to previous sum for current days value,then again add it to sum for total value
sum = sum+sum+0.01;
}
//printing output in cents.
std::cout << "Cents accumulated:" << sum*100 << " Number of days:" << n << std::endl;
return 0;
}

/*
sample output

Enter number of days: 3
Cents accumulated:7
Number of days:3
*/

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