0

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*/
2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by shyla
1

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()
{
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.