#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;



void isphone(int number)
{
	bool isphone = false;
	int size2= number.size();
	for (int i=0; i<size2; i++)
	{
		if(isdigit(number[i])&& size2>=4)
		{
			isphone=true;
		}
		else
		
		isphone = false;
	
	if(isphone=true)
	{
		cout<<"yes this is a phone number"<<endl;
	}
	else
	cout<<"Invalid number!"<<endl;
	}
}


//for testing purpose
int main(int argc, char* argv[])
{
	
	if (argc==2)
	
	isphone(string(argv[1]));


}

I was thinking to use this function to read the user input to see if they input the right number. But it just wont allow me to run! It has something like

testing.cpp: In function 'void isphone(int)':
testing.cpp:11: error: request for member 'size' in 'number', which is of non-class type 'int'
testing.cpp:14: error: invalid types 'int[int]' for array subscript
testing.cpp:22: warning: suggest parentheses around assignment used as truth value
testing.cpp: In function 'int main(int, char**)':
testing.cpp:38: error: 'isname' was not declared in this scope
Compilation failed.

O.O can someone plz help me figuring it out? I see no problem....or any suggestion to modify it?

>>if(isphone=true)

You are setting isphone to true in that loop, instead of testing it. You need to use the binary boolean operator :

if(isphone == true );

in fact, you can even do this :

if(isphone){
}

And for those errors, you named the boolean variable the same as your function name.
Also you are using numbers as if it were a string?

Here is your function without the errors*( not tested )

template<typename BeginItr, typename Fn1>
bool checkIf(BeginItr start, BeginItr end,const Fn1& f){
	while(start != end){
		if(!f(*start)) return false;
		++start;
	}
	return true;
}
bool hasAllDigits(const std::string& num){
	return checkIf(num.begin(),num.end(),isdigit);
}

bool isValidPhoneNumber(const std::string& num){
 return num.size() >= 9 && hasAllDigits(num);
}

That's work!!Thanks for the help :)

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.