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

List of all available Websheets


Viewing cpp/for/sum-mult-2-5 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>Write a program that lets the user type in a positive integer, <tt>n</tt>, and then sums all positive integers
   between 1 and n that are a multiple of either 2 or 5.</p>
<p>For example, if the user enters <tt>11</tt> we would want to sum the following values: <code>2 4 5 6 8 10</code> and output <tt>35</tt>.
Public permissions remove
Remarks
Comments, history, license, etc.
 
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>
#include <iomanip>
using namespace std;
int main() {
   int n;
   cout << "Enter a positive integer: " << endl;
   cin >> n;
\[
   int sum = 0;
   for( int i=2; i <= n; i++)
   {
      if(i%2==0 || i%5==0)
      {
         sum += i;
      }
   }
   cout << sum << 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": "11", "args": ""},
   {"stdin": "17", "args": ""},
   {"stdin": "1000", "args": ""},
   {"stdin": "1", "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'.