List of all available Websheets
Viewing cpp/conditionals/stoplight 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 | Ask the user to indicate what color a traffic light is. The user should type <tt>r</tt> for red and <tt>g</tt> for green. Output <tt>Stop!</tt> or <tt>Go!</tt> appropriately. |
Public permissions | |
Remarks Comments, history, license, etc. | 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() { char color; cout << "What color is the traffic light?" << endl; cin >> color; string result; \[ if(color == 'r') { result = "Stop!"; } else { result = "Go!"; } ]\ cout << result << 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": "r", "args": ""}, {"stdin": "g", "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'.