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
//******************************************************************
//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>
usingnamespace 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;
}