C++ char array Counts the number of letters in the user's first name.

Description

C++ char array Counts the number of letters in the user's first name.

#include <iostream>
using namespace std;
int main()/*ww w  .j av a 2 s  . c  o m*/
{
   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;
}



PreviousNext

Related