C++ static variable with the static declaration

Description

C++ static variable with the static declaration

#include <iostream>
using namespace std;
triple_it(int ctr);
int main()/*w ww.jav  a 2  s.  co  m*/
{
   int ctr;                    // Used in the for loop to  call a function 25 times.
   for (ctr=1; ctr<=25; ctr++)
   {
      triple_it(ctr);
   }        // Pass ctr to a function called triple_it().
   return 0;
}
triple_it(int ctr)
{
   static int total=0;                
   int ans;                        
   ans = ctr * 3;                 
   total += ans;  
   cout << "The number " << ctr << " multiplied by 3 is " << ans << "\n";
   if (total > 300)
   {
      cout << "The total of triple numbers is over 300 \n";
   }
   return 0;
}



PreviousNext

Related