In this examples we used (c++ ) continue as a replacement  of the if in the previous samples
Algorithm
this program is a slight modification from the previous one , if the numbers are negative the c++ continue statement does not have an effect on the flow of the program and it excute the rest of the for loop ( highlighed in red ), if the number is not not negtive( i,e positive) the continue statement let the program skip the rest of the for loop and continue to the next iteration

 

 

 

 

 

 

 

 

 


#include <iostream>
  using namespace std ;


  int main (){
int n , sum ;
int c[155];
sum = 0 ;
// This program let  you  calculate sum  of only positive numbers

cout<<" Enter the number of positive  numbers you want to add     " ;
  cin>> n ;


   for(int i=0 ; i<n; i++){
  cout<<" Enter the number  you want to add ";

          cin>>c[i];
          sum +=c[i] ;// Addition

         if(c[i]>0)
   continue ;     // skip the rest of  the for loop
             cout<<" \nYou entered a  negative number ";
             sum-= c[i] ;// concel the addiction

             i--; // decremetnt the counter  to cancel the increment

             }
  cout <<"The sum of the  positive numbers is    "<<sum <<endl <<endl<<endl;
     return 0 ;

  }