I wrote the following program, but my compiler (dev-cpp) says thereis an error w
ID: 3613004 • Letter: I
Question
I wrote the following program, but my compiler (dev-cpp) says thereis an error with the float command. I am unsure how to solveit.// Interest Calc.cpp
// To calculate amount gained or lost in interest
#include <iostream>
using namespace std;
int main()
{float Initial_Amount, Interest, Compoundments, Time,Total_Amount, Net_Change, Net_Change_Year, Net_Change_Month,Net_Change_Day;
cout << "Enter the Initial Amount: ";
cin >> Initial_Amount;
cout << "Enter Intrest (%): ";
cin >> Interest;
cout << "Number of Compoundments (Years): ";
cin >> Compoundments;
cout << "Time (Years): ";
cin >> Time;
Total_Amount =(Initial_Amount*(1+((Interest/100)/Compoundments))^(Compoundments*Time));
Net_Change = Total_Amount - Initial_Amount;
Net_Change_Year = Net_Change / Time;
Net_Change_Month = Net_Change / (Time * 12);
Net_Change_Day = Net_Change / (Time * 365);
cout << " This will result in a net change of $"<< Net_Change << " through this investment. ";
cout << " This comes out to be an average of $"<< Net_Change_Year << " a year, $"<<Net_Change_Month << " a month, or $" <<Net_Change_Day << " a day. ";
system("pause");
return 0;
}
Explanation / Answer
please rate - thanks C++ does not have an operator for exponentiation. you must use the function pow which takes 2 float parameters and isin the math library itis pow(base,exponent) so nm would be pow(n,m) I'm not sure I got your equation correct, since I don't know theformula) but it compiles // Interest Calc.cpp // To calculate amount gained or lost in interest #include #include using namespace std; int main() {float Initial_Amount, Interest, Compoundments, Time,Total_Amount, Net_Change, Net_Change_Year, Net_Change_Month,Net_Change_Day; cout > Initial_Amount; cout > Interest; cout > Compoundments; cout > Time; Total_Amount =Initial_Amount*pow((1+((Interest/100)/Compoundments)),Compoundments*Time); Net_Change = Total_Amount - Initial_Amount; Net_Change_Year = Net_Change / Time; Net_Change_Month = Net_Change / (Time * 12); Net_Change_Day = Net_Change / (Time * 365); coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.