If use starts with a space how to not cout it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
include <iostream> // libraries
#include <iomanip>
#include <string>

using namespace 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 . . .











Last edited on
Topic archived. No new replies allowed.