Quantcast
Channel: F-sharp – MoreCodes
Viewing all articles
Browse latest Browse all 30

C++, CPP Tutorial – Count Characters in a String

$
0
0

Write a program that counts the letter ‘a’ in the word “Programming”.

Solution:

#include<iostream>

using namespace std;

int main(){
 string strWord = "Programming";
 int intCount = 0;

 for(int i = 0; i < strWord.length(); i++){
  if(strWord[i] == 'a'){
   intCount++;
  }
 }

 cout << "There are " << intCount << " occurrence in the word.";

 return 0;
}

This is a free programming tutorial for you.

Check out more C++/CPP/CPlusPlus tutorials on this site.

here’s my github repository for the C++ codes of this blog:
ArjunAranetaCodes/MoreCodes-CPlusPlus

I used DevCPP in the development of this program.

For more information in CPP check out Wikipedia.

Feel free to leave some comments. Thank you 🙂
—-

Twitter – @MoreCodes
Facebook – https://www.facebook.com/morecodes/

—-

http://globeofblogs.com/


Viewing all articles
Browse latest Browse all 30

Latest Images

Trending Articles





Latest Images