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

#include <iostream> #include <cmath> using namespace std; int main () { int init

ID: 639882 • Letter: #

Question

#include <iostream>
#include <cmath>
using namespace std;

int main ()
{

int initial_investment;
int R;
int quarters;
double final_investment;
double profit;
double profit2;
double final_investment2;


cout << "Enter initial investment (dollars): ";
cin >> initial_investment;
cout << "Enter interest rate per year (percentage): ";
cin >> R;
cout << "Enter number of quarters: ";
cin >> quarters;

// calculates the final investment and the profit gained annually
    final_investment=initial_investment*(1+((R/100)^(quarters*4.0)));
    profit=final_investment-initial_investment;

    cout << "Value of your investment compounded yearly after "
   << quarters*4.0 << " years is " << final_investment
   << " dollars." << endl;

    cout << "Profit from your investment after" << quarters*4.0
   << "year(s) is " << profit << "dollars." << endl;

  
    /* computes the final value of the investment continuously compounded */
      final_investment2=initial_investment*1.0*(exp^((R/100)^(quarters*4.0)));
      profit2=final_investment2-initial_investment;
   
      cout << "Value of your same investment but continuously compounded is "
       << final_investment << " dollars." << endl;
      cout << "Profit from this statement is " << profit2 << " dollars."
       << endl;
      cout << "The difference between both investment types is "
       << profit2-profit << " dollars.";

      return (0);
}

Everything works fine except for lines 29 and 41(which are bolded). It comes up with the error "invalid operands of types

Explanation / Answer

working code

#include <iostream>
#include <cmath>
using namespace std;

int main ()
{

int initial_investment;
int R;
int quarters;
double final_investment;
double profit;
double profit2;
double final_investment2;


cout << "Enter initial investment (dollars): ";
cin >> initial_investment;
cout << "Enter interest rate per year (percentage): ";
cin >> R;
cout << "Enter number of quarters: ";
cin >> quarters;

// calculates the final investment and the profit gained annually
int cal = (1+((R/100)^(quarters*4)));
final_investment=initial_investment*cal;
profit=final_investment-initial_investment;

cout << "Value of your investment compounded yearly after "
<< quarters*4.0 << " years is " << final_investment
<< " dollars." << endl;

cout << "Profit from your investment after" << quarters*4.0
<< "year(s) is " << profit << "dollars." << endl;

  
/* computes the final value of the investment continuously compounded */
final_investment2=initial_investment*1.0*(((R/100)^(quarters*4)));
profit2=final_investment2-initial_investment;

cout << "Value of your same investment but continuously compounded is "
<< final_investment << " dollars." << endl;
cout << "Profit from this statement is " << profit2 << " dollars."
<< endl;
int res = profit2-profit;
cout << "The difference between both investment types is "
<< res<< " dollars.";

return (0);
}