my question is:
Write a function that accepts an integer parameter and returns its integer
square root. The function should throw an exception if it is passed an
integer that is not a perfect square. Demonstrate the function with a
suitable driver program.


i am getting that : Error 1 error C3861: 'squareRoot': identifier not found Exception
the line that's in bold

#include <iostream>
#include "ArithmeticHeader.h"
using namespace std;
int main()
{
	for (int c = 1;c <= 3; c++)
	{
		try
		{
			int number;
			int sqrt;
			cout << "Enter a number";
			cin >> number;
			[B]sqrt = squareRoot(number);[/B]
		cout << "The integer square root is: "<< sqrt << endl;
		}
		catch (SqrtException exc)
		{
			int badArg = exc.getArgument();
			cout << "Exception" << badArg
				<< " does not have an integer square root.  " << endl;
		}	
	}
	cout << endl << endl;
}
int squareRoot(int number)
{		
	int c = 0;
	while (c * c < number)
	c++;
	if(c * c == number) return c;
	throw SqrtException(number);
}
#ifndef ARITHMETICHEADER_H
#define ARITHMETICHEADER_H
#include <iostream>
using namespace std;

#include <iostream>
using namespace std;
class SqrtException
{
	int arg;
	public:
	SqrtException(int arg)
	{
	this->arg = arg;	
	}
	int getArgument(){return arg;}
};
#endif /* ARITHMETICHEADER.h*/

Recommended Answers

All 2 Replies

squareRoot is not declared before it's used. Either move the definition above main, or add a prototype:

#include <iostream>
#include "ArithmeticHeader.h"
using namespace std;

int squareRoot(int number);

int main()
{

simple arraignment can fix, and can change a lot.
appreciate the fast respond

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.