Counts the number of letters in the user's first name. - C++ Data Type

C++ examples for Data Type:char array

Description

Counts the number of letters in the user's first name.

Demo Code

#include <iostream>
using namespace std;
int main()//from   w  ww. j  a v  a2s.  c  om
{
   char name[15];           // Will hold user's first name
   int count=0;      // Will hold total characters in name
   // Get the user's first name
   cout << "What is your first name? ";
   cin >> name;
   while (name[count] > 0) // Loop until null zero reached.
   {
      count++;
   }                  // Add 1 to the count.
   cout << "Your name has " << count << " characters";
   return 0;
}

Result


Related Tutorials