While Loop Problem

I'm having a hard time completing this code. I believe something is wrong with my while loop but cannot figure out what. Any help would be appreciated.
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
//******************************************************************
//Purpose: Use a sentinel-controlled while loop to read characters from the //keyboard until an end of line(eol which is '\n') character is read.
//Print out the number of non-white characters read excluding the eol character.

//Note: a white space can be blank(' '), tab('\t') or a new line('\n')
//******************************************************************/

#include <iostream>

using namespace std;

int main()
{
     //varible declaration
     char letter;
     int counter;
    
     cout <<"\nStart to get character..."<<endl;

     cin >> letter;   // Read the first character 
     cin.get(letter); // Notice get function for reading white spaces 
     counter = 0;     // Initialize the counter 
     
     // loop until the end of the line character
     // Write while loop here
  
     while ( letter != '\n')	
     {
	
	counter++;    // for non-white character increment the counter
   	cin >> letter;
	
     }		
    
     //show the result
        cout <<"\nThe number of charater is "<< counter << endl;

        cout <<"\nFinish running"<<endl;
        return 0;
}
Topic archived. No new replies allowed.