HOW TO CREATE A LOOP FOR THIS ???

closed account (z6f9LyTq)
Calculate for some polygons (sum of interior angles, each interior angle, each exterior angle.

Ask the user to input the max number of sides of the figure

Generate the following report starting at a 3-sided figure to the number of sides the user input earlier.


So far what I have:
#include <iostream.h>
#include <math.h>
#include <iomanip.h>


int main( )

{

cout.setf(ios::fixed,ios::floatfield);
cout.setf(ios::showpoint);
cout<<setprecision(1);



int n;
double intsum = 0;
double Interior = 0;
double Exterior = 0;



cout << "What is the maximum sides of the polygon? ";
cin >> n;



PLEASE HELP?!?!?!?!
I don't think you need loops for this.... just a bit of maths to understand whats going on. And please use code tags for your code and is it really necessary to use ALL CAPS IN YOUR TITLE?

I'm assuming you are talking about regular polygons
First you need to check if input size is greater than 2 (As you can't have a closed shape with 2 sides). if condition for that...
Now to get the sum of the interior angle. Think about the sum of interior angles in some shapes: Triangle = 180, Square = 360, Pentagon = 540..what are you doing each time? Adding 180. So in general to get the sum of an n-sided polygon you could do something like this.
int Interior_sum = (n-2)*180
I'll leave you to figure out the rest for yourself
Last edited on
closed account (z6f9LyTq)
I know the math but it HAS to be a loop, that is the assignment
closed account (j3Rz8vqX)
1
2
3
4
5
6
7
cout << "What is the maximum sides of the polygon? ";
cin >> n;

for(/*BLANK*/;/*BLANK*/ < /*BLANK*/;/*BLNAK++*/)
{
    /*BLANK Arithmetic*/
}


Non efficient, but if you want a loop, that's one.

Now the question is what is your loop going to do?

An example of for-loops:
http://www.tutorialspoint.com/cplusplus/cpp_for_loop.htm

Logic and understanding of flow controls:
http://www.cplusplus.com/doc/tutorial/control/
Last edited on
Kindof don't see the point in using loops here.....
Everything to be calculated can be done with single statements ...
Perhaps your loop can be to keep adding 180 for each increase in "n". Pretty pointless doing that but it HAS to be a loop you create lots of loops for no reason.
Last edited on
closed account (z6f9LyTq)
I know it's kind of pointless, but that's what our instructor said.It has to look like:

CHARCTERISTICS OF POLYGONS

Number Sum of Each Each

of Interior Interior Exterior

Sides Angles Angle Angle



3 180 60 120

4

5

.

.

.

n


(n being the maximum number of sides the user input)
closed account (j3Rz8vqX)
My only guess is, instead of using arithmetic, you're to use accumulators.
Oh you want to find the sum of angles/angles for polygons up to n. You were making it sound like you only had to calculate the angles for 1 polygon of size n.
Yeah you would use a loop for this so something like
1
2
3
4
5
for(int i = 3; i <= n; i++)
{ *
   * All your calculations/print statements here
   *
}

Topic archived. No new replies allowed.