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

List of all available Websheets


Viewing cpp/division-modulo/middle2 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
 
Given a 4-digit year: <tt>YYYY</tt>, ouput the middle 2 digits only.
So if the user enters <tt>2104</tt>, output only <tt>10</tt>
Public permissions remove
Remarks
Comments, history, license, etc.
 
Copied from problem cpp/division-modulo/birth-year (author: redekopp@usc.edu)
Copied from problem cpp/cin/building_floor (author: redekopp@usc.edu)
Copied from problem cpp/cin/average (author: redekopp@usc.edu)
Copied from problem cpp/var-expr/in_n_days (author: redekopp@usc.edu)
Copied from problem cpp/var-expr/char_arith (author: redekopp@usc.edu)
Copied from problem cpp/var-expr/hello (author: daveagp@gmail.com)
remove
Engine
Template / Reference solution
 
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
   // variable for the year
   int year, middle2;
   cout << "Enter the year: " << endl;
   cin >> year;
   
   \[ 
      middle2 = (year / 10) % 100;
      ]\
   
   cout << "Middle 2 digits: " << middle2 << 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":"1234", "args":[]},
   {"stdin":"1978", "args":[]},
   {"stdin":"2104", "args":[]},
   {"stdin":"1995", "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'.