C++ help! Don't know how to fix program

I recently wrote a program for C++ to calculate a circular bolt pattern and i ran into a problem of not being able to actually run the program. I keep getting an error expected primary-expression before "else" on line 57 and i honestly have zero clue as to why. Any help would be much appreciated, and how i can avoid this for future reference.

#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main ()//
{
char YN = 'Y' ;

// while loop
while( YN== 'Y')
{ //start of a section for the while loop

//variables
float x, y , Diameter_of_circle, points_loc;
float degrees, x2, y2, radius, full_circle, first_angle, last_angle;
int points;

cout<<setprecision(2); //number of digits after decimal point
cout<<fixed<<showpoint;

cout<< "Enter the number of points: ";
cin>> points;
cout<< "Enter the Diameter of the circle: ";
cin >> Diameter_of_circle;
cout<< "Location of circle center on x: " ;
cin>> x;
cout<< "Location of circle center on Y: " ;
cin>> y;

{ //Start a while loop
// variable declaration:
int YN;
cout<< "Is this a full bolt circle? YES(Y) or NO(N) " ;
cin >> YN;
// loop execution
if ( YN = 2);
{
cout<< "Location of the first Angle: ";
cin>> first_angle;
cout<< endl;

//math equations using the points and angles
degrees= 6.2831*(180/M_PI);
points_loc= (degrees / points);
radius= (Diameter_of_circle/2);

//Loop output
for ( float i= first_angle; i<points+first_angle; i++)
{
//start of section for-loop
cout<< "At: "; cout<< setprecision(2)<< points_loc*i; cout<< " degrees ";
cout<< " X: "; cout<< (x +( radius*cos(points_loc*i)));
cout<< " Y: "; cout<< (y + (radius*sin(points_loc*i)));
cout<< endl;//end of section for-loop
}
}
else(YN > 2 )
{
{
cout<< "Location of the first Angle: ";
cin>> first_angle;
cout<< "Location of the Last Angle: ";
cin>> last_angle;
cout<< endl;

//math equations for giving the points and angle
degrees= 6.2831*(180/M_PI);
points_loc= (degrees / points);
radius= (Diameter_of_circle/2);

//Loop output
for ( float i= first_angle; i<points+first_angle<180; i++)
{
//start of section for-loop
cout<< "At: "; cout<< setprecision(2)<< points_loc*i; cout<< " degrees ";
cout<< " X: "; cout<< (x +( radius*cos(points_loc*i)));
cout<< " Y: "; cout<< (y + (radius*sin(points_loc*i)));
cout<< endl;}//end of section for-loop
}
}
}
cout << "would you like to do it again? YES(Y) or NO(N)"<< endl;
cin>> YN;
//end loop for asking
//end of section for while loop
}
system("Pause");
return 0 ;
You can't use else(YN>2) in that way. Use else{} or else if(YN>2){}. Most likely it is that, but havent learned this language completely yet so might be wrong


Edit your post and put your code in code tags (the <> button to the right while editing)
Also, indent the code properly, this will show you the issues with your braces. Failing to indent your code appropriately will make finding problems hard, some helpers on this site wont even try to read it if you dont make that effort.

if ( YN = 2); this is an assignment, you mean ==, to avoid this in future always put the constant on the left as follows

if ( 2 == YN); if you miss an equals the compiler will complain

as strike089 said
else(YN > 2 ) should be else if (YN > 2 )

there is also a missing "}" from the end of the code.
Topic archived. No new replies allowed.