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

List of all available Websheets


Viewing cpp/cin/average 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
 
Write a program to compute the average of two integers and output it to the screen.
Public permissions remove
Remarks
Comments, history, license, etc.
 
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() {
   int num1, num2;
   double average;
   
   cout << "Enter two integers: " << endl;
  \[
   cin >> num1 >> num2;
  ]\
   
   
  \[
   average = (num1 + num2) / 2.0;
  ]\
  cout << "The average of " << num1 << " and " 
     << num2 << " is " << average << 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":"5 3", "args":[]},
   {"stdin":"1 100", "args":[]},
   {"stdin":"3 16", "args":[]},
   {"stdin":"-7 5", "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'.