Counts the number of letters in the user's first name, while Loop until null zero is reached. - C++ Data Type

C++ examples for Data Type:char array

Description

Counts the number of letters in the user's first name, while Loop until null zero is reached.

Demo Code

#include <iostream>
using namespace std;
int main()/* w  w w .  java  2  s  .c  o  m*/
{
   char name[15];
   int count=0;  
   // Get the user's first name
   cout << "What is your first name? ";
   cin >> name;
   while (name[count])
   {
      count++;
   }                  
   cout << "Your name has " << count << " characters";
   return 0;
}

Result


Related Tutorials