include <iostream> // libraries
#include <iomanip>
#include <string>
usingnamespace std;
int main()
{
char str[80];
int i;
cout << "enter a string. Remeber to hit space at the end"<<endl; // prompting user
cin.getline(str,80); // geting line
cout<<endl;
i =0;
while (str[i]!='\0' || str[i] ==' ') // Loop until you reach the null character
{
int cnt = 0; // digit counter
int counter=0; // char counter
//loop until I get to the space character
while(str[i] != ' '){
cout << str[i];
if (str[i]>='0' && str[i] <='9'){
cnt+=1;
}
counter+=1; i+=1;
}
if(cnt == counter) //if digit counter == char counter then all my charcters are numbers
{
cout << " is a nunber" << endl;
}
else //if not then its not a number
{
cout << " is not a number" << endl;
}
i++;
}
}
enter a string. Remeber to hit space at the end
sadfl aw
is a nunber
is a nunber
sadfl is not a number
aw is not a number
Press any key to continue . . .