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

List of all available Websheets


Viewing cpp/control/guessing 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>Complete the program to allow the user to continue guessing numbers until their input matches the secret number.</p>
<p>Before each guess input, you should output a prompt: <tt>Enter your guess.</tt></p>
Public permissions remove
Remarks
Comments, history, license, etc.
 
Copied from problem cpp/control/primes (author: daveagp@gmail.com)
remove
Engine
Template / Reference solution
 
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
   int guess;
   int secretNum = 42; // Eventually, replace with random selection
   // Start the guessing game
\[
   cout << "Enter your guess." << endl;
   cin >> guess;
   while(guess != secretNum) {
      /* What should we do here? */   
      cout << "Enter your guess." << endl;
      cin >> guess;
   }
   cout << "You got it!" << endl;
\show:
   cout << "Enter your guess." << endl;
   cin >> guess;
   if(guess != secretNum) {
      /* What should we do here? */   
   }
   else {
      cout << "You got it!" << 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": "42"},
   {"stdin": "1 2 3 4 5 6 7 8 9 10 42 43 44 45"}
]
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'.