character counting program error

I write character counting program(lowercase letter, uppercase latter, numbers, punctuations and white space) but program doesnt count first character. I cant find error please help...And many thanks....

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <stdio.h>
#include <ctype.h>

using namespace std;

int main()
{

char array;
int i = 0, lowercase = 0, uppercase = 0, numbers = 0, space = 0, punctuation = 0, total;

cout << "Enter a sentence(program terminated with the @ character): "<<endl;
cin >> array;
cout <<endl;

for (i=0; i<=100; i++)
{
  cin.get(array);

  if (array=='@')
  {
     break;
  }

      if(islower(array)){
     lowercase++;

   }

     else if (isupper(array)){
     uppercase++;

   }

     else if (isdigit(array)){
     numbers++;

   }

     else if (isspace(array)){
     space++;

   }

     else if (ispunct(array)){
     punctuation++;

   }           

     else
     i++;
}

total = lowercase + uppercase + numbers + space + punctuation;

cout << "Your sentence has " << lowercase << " lowercase letters." << endl;

cout << "Your sentence has " << uppercase << " uppercase letters." <<endl;

cout << "Your sentence has " << numbers << " numbers." <<endl;

cout << "Your sentence has " << space << " spaces." <<endl;

cout << "Your sentence has " << punctuation << " punctuations." <<endl;

cout << "Your sentence has " << total << " total characters." <<endl;

getchar();

system("pause");
return 0;
}
Last edited on
Line 19: Reading in another character before you've used the first one.
Topic archived. No new replies allowed.