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

List of all available Websheets


Viewing cpp/for/polydeg 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 know the interior angles of a triangle sum to 180 degrees, the angles of a square sum to 360, and so on.</p>
<p>In general the sum of degrees for the interior angles of an n-sided polygon is: (n-2) × 180°.</p>
<p>Write a program that first asks the user (no prompt needed) for how many sides a polygon has (call this number <em>n</em>.
   Then let the user enter <em>n</em> integers representing the degrees of each of the n interior angles (no prompt needed).
   Finally, check whether the angles they have entered sum to the appropriate number of degrees for an n-sided polygon and output: 
   <tt>Correct</tt> or <tt>Incorrect</tt></p>
<p><strong>You should use a <tt>for</tt> loop</strong> to sum the angles.</p>
Public permissions remove
Remarks
Comments, history, license, etc.
 
Copied from problem cpp/for/blastoff (author: redekopp@usc.edu)
Copied from problem cpp/while/blastoff (author: redekopp@usc.edu)
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 n;
   cin >> n;
\[
   int sum = 0;
   int angle;
   for(int i=0; i < n; i++){
      cin >> angle;
      sum += angle; 
   }
   if(sum == (n-2)*180){
      cout << "Correct" << endl;  
   }
   else {
      cout << "Incorrect" << 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": "4 90 90 90 90", "args": ""},
   {"stdin": "4 70 90 150 90", "args": ""},
   {"stdin": "8 135 135 135 135 135 135 135 135", "args": ""},
   {"stdin": "5 108 108 108 108 108", "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'.