demonstrates enums, counts words in phrase : enum « Data Type « C++






demonstrates enums, counts words in phrase

   
#include <iostream>   
  using namespace std;   
  #include <conio.h>
    
  enum itsaWord { NO, YES };
    
  int main(){   
     itsaWord isWord = NO;       

     char ch = 'a';            
     int wordcount = 0;        
    
     cout << "Enter a phrase:\n";   
     do {   
        ch = getche();         
        if(ch==' ' || ch=='\r'){   
           if( isWord == YES ){                 
              wordcount++;      
              isWord = NO;      
           }   
        }else if( isWord == NO ){
           isWord = YES;     
        }
     } while( ch != '\r' );     
     cout << wordcount;   
     return 0;   
  }
  
    
    
  








Related examples in the same category

1.Using consts and enums in Arrays
2.Using bit fields.
3.demonstrates enum types
4.demonstrates enumerations