#include <iostream>

#include <string>

using namespace std;


int GCD(int x, int y);

int main ()

{


	int ans, num, a, b, c, d, e, f, g, y;

	int h = 0;

	int w = 0;

	char ans2;

	char ans3;

	cout << "[1] Math algorithms " << endl;

	cout << "[2] Figures " << endl;

	cout << "[3] Exit " << endl;

	cout << "Enter your choice. ";

	cin >> ans;

	cout << endl;


	if (ans == 1)

	{ 

		cout << endl;

		cout << " [e] Use the EUCLIDEAN algorithm " << endl;

		cout << " [f] Generate an ULAM sequence " << endl;

		cout << " [g] Generate a FIBONACCI Sequence " << endl;

		cout << " [y] Use FERMAT's little test " << endl;

		cout << " Enter your choice. ";

		cin >> ans3;



		if (ans3 == 'e')

			cout << endl;

		{

			int x,y,temp, remainder;

			// read in the two integers

			cout << endl ;

			cout << "Enter the first number (positive integer) : " ;

			cin >> x ;

			cout << "Enter the second number (positive integer) : " ;

			cin >> y ;

			//echo inputs

			cout << "Input numbers are: " << x << " , " << y << endl ;

			if(x < y)

			{ // exchange values of x and y

				x=x+y;

				y=x-y;

				x=x-y;

			}

			/* At this point we will always have x >= y */

			//Initialize remainder.

			while ( (x%y)!=0 )

			{

				x=x%y;

				x=x+y;

				y=x-y;

				x=x-y;

			}

			// display the result

			cout << endl ;

			cout << "The GCD is: " << y << endl ;

			system("pause>nul");
		}

		else if (ans3 == 'f')

		{
			int iCount = 1;

			int numb;


			cout<<"enter a number: ";

			cin>>numb;


			int iTemp = numb;


			while (iTemp != 1)

			{


				if (iTemp % 2 == 0)

				{

					iTemp /= 2;

				}


				else

				{

					iTemp = iTemp * 3 + 1;

				}

				++iCount;

			}

			cout << "Cycle length of " << numb << " is " << iCount << endl;

			system ("pause");

		}

	}








	if (ans == 2);

	{ 

		cout << " [a] Print a Rectangle " << endl;

		cout << " [b] Print a Triangle " << endl;

		cout << " [c] Print a Rectangle Outline " << endl;

		cout << " Enter your choice. ";

		cin >> ans2;

		{

			if (ans2 == 'a')

				cout << endl;

			{ int width, height;


			cout<< "input height and width as: x[enter], y[enter]"<<'\n';


			while (cin >> width >> height) 

			{

				for (int row=0; row<height; row++) 

				{

					for (int col=0; col<width; col++) 

					{

						cout << "*";

					}

					cout << endl; // end the line of stars.

				}

			}



			}


			if (ans2 == 'b')

				cout << endl;

			{


				int size;

				cout<<"INPUT the Size of the TRIANGLE"<<'\n';

				while (cin >> size) 

				{

					for (int row=1; row<=size; row++) 

					{

						for (int col=0; col<row; col++) 

						{

							cout << "*";

						}

						cout << endl; 

					}

				}

			}


			if (ans2 == 'c')

				cout << endl;

			{


				{ 

					int MyRow, MyCol; char MyChar; //this are my variables

					cout << "WELCOME TO THE RECTANGLE PROGRAM" << endl << endl;


					cout << "Enter any character to be the outline of the rectangle: "; //this will prompt for a character to be used for drawing the rectangle

					cin >> MyChar;

					cout << "Enter the number of columns (up to 79): "; //this will prompt for the number of columns the rectangle will have

					cin >> MyCol;

					cout << "Enter the number of rows (up to 22): "; //this will prompt for the number of rows the rectangle will have

					cin >> MyRow;

					string spaces( MyCol-2, ' ' ); // this string "spaces" will draw as many spaces as the user input for columns minus 2

					if ((MyCol <= 79) && (MyRow <= 22))

					{ //this "if" is to limit the number of columns and rows to 79 and 22 respectively


						for ( int y = 0; y < MyCol; y++) //this "for" loop will draw the top row

						{

							cout << MyChar;

						}

						for ( int y = 2; y < MyRow; y++) //this "for" loop will draw the rows in the middle

						{

							cout <<"\n"<< MyChar << spaces << MyChar; //it consist of a starting character, empty spaces, and an ending character

						}

						cout<< endl; //this creates a new line for the bottom row

						for ( int y = 0; y < MyCol; y++) //this is the bottom row. Just like the top row

						{

							cout << MyChar;

						}

						cout<< endl; //this creates a new line for any message to appear below the rectangle


					}

				}

			}

		}

	}

	return 0;}

The error is at line 121. I cant compile this code due to the error. please help me

Your if - line 58

if (ans3 == 'e')
cout << endl;

probably should be

if (ans3 == 'e')
{
cout << endl;

Edited 6 Years Ago by gerard4143: n/a

I'm sorry for posting the whole code here, i think the problem is not really on line 121.

gerard4143 i've tried your suggestion, b

I'm sorry for posting the whole code here, i think the problem is not really on line 121.

gerard4143 i've tried your suggestion, b

It's not, it's on line 58, like Gerard said. It's flagging 121 because your error around Line 58 closes the if's scope prematurely thus preventing it from associating with an else. As a result, when the compiler gets to the else on Line 121 there is no open if available for it to associate the else with so it throws an error and lists the current line as the error location.

You'll get the same result on any compiler because you have written syntactically correct code up until that point. Compilers simply aren't smart enough to go back 50+ lines to find the actual error. Once a compiler is done with a particular line, it pretty-much forgets that it exists.

Edited 6 Years Ago by Fbody: n/a

This article has been dead for over six months. Start a new discussion instead.