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

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.
PropertyValue
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 remove
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)
remove
Engine
Template / Reference solution
 
#include <iostream>
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 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'.