List of all available Websheets
Viewing cpp/while/goldilocks by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | <p>Write a program that helps Goldilocks find the bowl of porridge that is just right.</p> <p>The user will enter a value representing how hot a bowl of porridge is on a scale of 1-10. Use the following table to rate the bowl:</p> <table> <tr> <th>Input value</th><th>Output Message</th> </tr> <tr> <td><tt>1-4</tt></td><td><tt>Too cold!</tt></td> </tr> <tr> <td><tt>5</tt></td><td><tt>Just right!</tt></td> </tr> <tr> <td><tt>6-10</tt></td><td><tt>Too hot!</tt></td> </tr> </table> <p>Your program should continue taking in new values <strong>UNTIL</strong> you find a bowl that is <em>just right</em>, at which point the program should quit.</p> <p>You <strong>need not output a prompt (English-language message) to the user</strong> but can just use <tt>cin</tt> alone.</p> |
Public permissions | |
Remarks Comments, history, license, etc. | 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) |
Engine | |
Template / Reference solution |
using namespace std; int main() { int howHot; \[ bool found = false; while(!found){ cin >> howHot; if(howHot >5 ) cout << "Too hot!" << endl; else if(howHot < 5 ) cout << "Too cold!" << endl; else { cout << "Just right!" << endl; found = true; } } ]\ 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": "4 6 5", "args": ""}, {"stdin": "1 1 5 5", "args": ""}, {"stdin": "5", "args": ""}, {"stdin": "1 9 2 8 3 7 4 6 5", "args": ""} ] |
Solution visibility |
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'.