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

List of all available Websheets


Viewing cpp/while/turn360 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>You are driving in downtown which has a grid-like street layout where you can only turn right or left 90 degrees.
   Suppose you are heading north initially but then can arbitrarily choose to turn left or right at any street. 
   Write a program that will track your heading and exits as soon as you have completed some sequence of turns that result in a full 360 degree cycle
   <strong>either clockwise or counter-clockwise.</strong></p>
<p>The user will continue to enter the turns they choose to make by typing <tt>r</tt> for right and <tt>l</tt> for left.  You may assume no other 
character is input.</p>
<p>You <strong>need not output a prompt (English-language message) to the user</strong> but can just use <tt>cin</tt> to take in turn values.</p>
<p>When you detect a full 360 degree cycle, output <strong><tt>Clockwise</tt> or <tt>Counterclockwise</tt></strong>
   based on the direction of the 360-degree turn.</p>
Public permissions remove
Remarks
Comments, history, license, etc.
 
Copied from problem cpp/while/goldilocks (author: redekopp@usc.edu)
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)
remove
Engine
Template / Reference solution
 
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
   \[
   int dir = 0;
   char turn;
   while(dir != -4 && dir != 4){
      cin >> turn;
      if(turn == 'r'){
         dir++;
      }
      else {
         dir--;
      }
   }
   if(dir == 4){
      cout << "Clockwise" << endl;
   }
   else {
      cout << "Counterclockwise" << 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 r r r", "args": ""},
   {"stdin": "l l l l", "args": ""},
   {"stdin": "r l l r r r r l r r", "args": ""},
   {"stdin": "l r r l l l l r l l", "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'.