Counting in C++

Published on: August 21, 2010

In today's Beginner C++ Tutorial, I give you an explanation on how to count in C++. I'm already sure you know how to count without it but it is a neat function in C++ that you can use to your benefits for any future programs you plan on running. And you have actually seen how the counting works when I showed you both the "for" and "while" loops as well as a few other tutorials of mine that require some sort of counting. Today however, I go into a bit more details on how the counting works.

I hope you enjoy the video and if you have any requests feel free to let me know.

Remember to checkout the Codesnip below to review the C++ code yourself! Feel free to copy the code, but I ask that you please provide credit if you leave the code unchanged when you use it.

Codesnip:

//Programmer: Nazmus
//Program:  Counting
//Purpose:  Learning to count in C++ with Test Grades
//Website:  EasyProgramming.net

#include <iostream>
using namespace std;

void main()
{
  int pass, fail, grade, i;
  pass = 0;
  fail = 0;
  i = 1;

  while(i<=10){
   cout << "Please enter the grade: ";
   cin >> grade;

   if(grade >=65) pass++;
   else fail++;

   i++;
  }

  cout << "There are " << pass << " passes and " << fail << 
   " failures in the class." << endl;

 system("pause");
}



Comments: