Here's a simple program to do what you ask. Remember this will only take a word not a string, so if you plan on having spaces this will NOT work, but in your original post you said "word".
Code:
#include <stdio.h>
#include <ctype.h>
#include <fstream.h>
int main( void )
{
ofstream fout("MyProjects\\info.dat");
char Array[255];
int nVowels = 0, nCons = 0;
cout << "Enter a word: ";
cin >> Array;
for( register int i = 0; i < strlen( Array ); i++ )
{
// Convert letter to lower-case
Array[i] = tolower( Array[i] );
// Switch on the character to determine type
switch( Array[i] )
{
case 'a':
nVowels++;
break;
case 'e':
nVowels++;
break;
case 'i':
nVowels++;
break;
case 'o':
nVowels++;
break;
case 'u':
nVowels++;
break;
default:
nCons++;
break;
}
}
// Output data to a file
fout << "Word is " << Array << endl;
fout << "Number of Vowels - " << nVowels << endl;
fout << "Number of Consonants - " << nCons << endl;
fout << "Total letters in word - " << (nCons + nVowels) << endl;
// Close the file after writing to it
fout.close();
return( 0 );
}