if statement in a function

I am trying to determine if these floats are properly formatted. I created a function that is designed to increment ctr if the float contains either a digit or a '.' and increment ctr1 if it is anything else but my counters are not counting properly. I was wondering if any one had any suggestions.
thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int checksize (char buffersize [81])
{
  int ctr = 0;
  int ctr1 = 0;
  for (int x = 0; buffersize[x] != '\0'; x++)
        {
  if ((isdigit (buffersize [x])) || ('.'))
                {
    ctr++;
                }
   else
                {
    ctr1++;
                }
        }
  cout << ctr << "   " << ctr1 << "  " << buffersize << endl;

}

Last edited on
I suggest looking very carefully at line 7.

Also, your indentation style is pretty bad, I recommend choosing a better one.
i am very aware that line 7 is the problem! isn't it saying that if buffer [x] is either a digit or a '.' then increment ctr?
avalesky wrote:
isn't it saying that if buffer [x] is either a digit or a '.' then increment ctr?
No, it is saying 'if the current character is a is a digit, or if the period character value does not equal zero, then blah'. The period character is, of course, not equal to zero, so the condition is always true.
Last edited on
thank you so much!

if ((isdigit (buffersize [x])) || (buffersize [x] == '.'))
Topic archived. No new replies allowed.