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

List of all available Websheets


Viewing cpp/nestedloops/etox-range by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
PropertyValue
Description
html markup
shown to student
 
<p>Convert the program you wrote in a previous exercise that computes e<sup>x</sup> to now
take in a lower limit, <tt>x0</tt>  which is inclusive and an upper limit, <tt>x1</tt>,
   which is exclusive and then prints out all the values of e<sup>x</sup> where x ranges from
   <tt>[x0, x1)</tt> in increments of <tt>0.2</tt>.</p>
<p>For example, if the user enters <tt>0.6</tt> and <tt>2.2</tt> you should output the approximation for: e^0.6, e^0.8, e^1.0, e^1.2, e^1.4, e^1.6, e^1.8, and e^2.0.  Notice we don't output e^2.2 since the upper limit is exclusive</p>
<p>We have started you with the code to compute an approximation of e<sup>x</sup> for a single value of <tt>x</tt>. Modify it to now produce the desired output.</p>
Public permissions remove
Remarks
Comments, history, license, etc.
 
Copied from problem cpp/for/sum-mult-2-5 (author: redekopp@usc.edu)
Copied from problem cpp/for/blastoff (author: redekopp@usc.edu)
Copied from problem cpp/while/blastoff (author: redekopp@usc.edu)
Copied from problem cpp/while/goldilocks (author: redekopp@usc.edu)
Copied from problem cpp/while/sum50 (author: redekopp@usc.edu)
Copied from problem cpp/conditionals/rps (author: redekopp@usc.edu)
Copied from problem cpp/conditionals/taxbrackets (author: redekopp@usc.edu)
Copied from problem cpp/conditionals/nestedec (author: redekopp@usc.edu)
Copied from problem cpp/conditionals/extracredit (author: redekopp@usc.edu)
Copied from problem cpp/control/flag (author: daveagp@gmail.com)
remove
Engine
Template / Reference solution
 
#include <iostream>
using namespace std;
int main()
{
   \[
   double x;
   double x0, x1;
   cin >> x0 >> x1;
   for(x=x0; x < x1; x += 0.2){     
      double x_to_i = 1;
      int i_fact = 1;
      double e_x = 1;
      for(int i=1; i < 10; i++){
         x_to_i *= x;
         i_fact *= i;
         e_x += x_to_i / i_fact;
      }
      cout << e_x << endl;       
   }
   \show:
   double x;
   cin >> x;
   double x_to_i = 1;
   int i_fact = 1;
   double e_x = 1;
   for(int i=1; i < 10; i++){
      x_to_i *= x;
      i_fact *= i;
      e_x += x_to_i / i_fact;
   }
   cout << e_x << endl;       
   ]\
}
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": "0.6 2.2", "args": ""},
   {"stdin": "-1.0 1.2", "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'.