c++ - cout-ing symbol after every n times? -


i want combine symbol "." result , add after every 8 (characters or numbers) tried use loop couldn't ,here's code it's kind of sum subtract smaller number bigger number , cout symbol of bigger number "a" @ first process , keep subtracting smaller bigger till end. want cout-ing "." before "a" , after every 8 processes:

#include<iostream> using namespace std; int main() {     int a=26;     int b=7;     cout<<endl;     while(a!=b)     {         if(a>b)         {             a=a-b;             if(a==b){cout<<"ab";}             else cout<<"a";         }         else         {             b=b-a;             if(a==b){cout<<"ba";}             else cout<<"b";         }     }     cout<<endl;     getchar();     return 0; } 

keep int count variable. increment ++count @ every process, , print whatever want when count becomes 8.

something this:

int main() {     int a=26;     int b=7;     char bigger='.'; //i suppose want print periodically!     int count = 0;     cout << bigger;     while(a!=b)     {         if(a>b)         {             a=a-b;             if(a==b) { cout << "ab"; count += 2;}             else { cout << "a"; ++count; }         }         else         {             b=b-a;             if(a==b) { cout << "ba"; count += 2; }             else { cout << "b"; ++count; }         }         if(count == 8)         {             cout << bigger;             count = 0; //reset 0         }     }     cout<<endl;     getchar();     return 0; } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -