Not logged in. Log in with GitHub. About Websheets.

List of all available Websheets


Viewing cpp/cs102/practiceLab4/apy by jmell@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
PropertyValue
Description
html markup
shown to student
 
Write a program to compute the Annual Percentage Yield which is given by:  
$$\Large APY = ({ 1 + \frac{r}{n}})^n - 1$$
where r is the interest rate expressed as a decimal (e.g. 3% should be entered as <code>0.03</code>) and n is the number of times compounded.
Public permissions remove
Remarks
Comments, history, license, etc.
 
Copied from problem cpp/cs102/practice4/apy (author: redekopp@usc.edu)
Copied from problem cpp/cin/average (author: redekopp@usc.edu)
Copied from problem cpp/var-expr/in_n_days (author: redekopp@usc.edu)
Copied from problem cpp/var-expr/char_arith (author: redekopp@usc.edu)
Copied from problem cpp/var-expr/hello (author: daveagp@gmail.com)
remove
Engine
Template / Reference solution
 
#include <iostream>
#include <cmath>
using namespace std;
int main() {
   cout << "Enter r and n: " << endl;     
   \[
  double r;
  int n;     
  cin >> r >> n;
  double apy = pow( (1 + r/n), n ) - 1;
 ]\
      
  // Print out the answer (add your variable with the answer in the blank)
  cout << "APY is " << \[apy]\ << endl;
   
  return 0;
}
C++ test suite
json list of stdin/args tests
e.g. [{"stdin":"hi", "args":["4", "5"]},
{"stdin":"noargs"}]

to just run once with no input use [{}]
 
[
   {"stdin":"5 3", "args":[]},
   {"stdin":"1 100", "args":[]},
   {"stdin":"3 16", "args":[]},
   {"stdin":"-7 5", "args":[]}
   
]
Solution visibility remove


Optional properties:

Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.