C++ double compu teInterest(double principal, double rate, i nt months) this fun
ID: 3871637 • Letter: C
Question
C++
double compu teInterest(double principal, double rate, i nt months) this function is named computelnterest; it returns a double for output, and receives two doubles and an int for input. create a double variable named totalInterest, and set it equal to 0.0 double tota!Interest = 0.0; next create a for-loop that starts an int variable(named i) at 0, iterates while i is less than 2. 3. months, and increments i by 1 for the post-action. Here is the for-loop structure for (initial state; condition; post-action)Explanation / Answer
#include<iostream>
using namespace std;
// step1
double computeInterest(double principal, double rate, int month)
{
// step 2
double totalInterest = 0.0;
// step 3
for(int i=0;i<month;i++)
{
// step 4
double interest = principal * rate;
// step 5
principal += interest;
totalInterest += interest;
}
// step 6
return totalInterest;
}
main()
{
// sample run
cout << computeInterest(100, 0.05, 2);
}
#include<iostream>
using namespace std;
// step1
double computeInterest(double principal, double rate, int month)
{
// step 2
double totalInterest = 0.0;
// step 3
for(int i=0;i<month;i++)
{
// step 4
double interest = principal * rate;
// step 5
principal += interest;
totalInterest += interest;
}
// step 6
return totalInterest;
}
main()
{
// sample run
cout << computeInterest(100, 0.05, 2);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.