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

List of all available Websheets


Viewing cpp/while/sum50 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 repeatedly asks the user to input an integer until the sum of the inputs reaches at least 50. 
   Your program should also output <em>how many</em> integers were input to reach the sum of 50 or more.</p>
<p>On each iteration (repetition) output the prompt: <tt>"Input:"</tt> and a newline.</p>
<p>At the end of the program just output the total sum on 1 line (no other text message), and the number of integers that were entered on the next (again no other text message).</p>
Public permissions remove
Remarks
Comments, history, license, etc.
 
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 sum = 0;
   int count = 0;
   int num;
   while(sum < 50){
      cout << "Input:" << endl;
      cin >> num;
      sum += num;
      count++;
   }
   cout << sum << endl;
   cout << count << 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": "50", "args": ""},
   {"stdin": "5 10 20 14 100", "args": ""},
   {"stdin": "5 5 5 5 5 5 5 5 5 5", "args": ""},
   {"stdin": "1 9 8 2 7 3 6 4 5 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'.