Reputation: 27
I want to combine the symbol "." with the result and add it after every 8 (characters or numbers) i tried to use for loop but i couldn't ,here's my code it's a kind of sum that subtract the smaller number from the bigger number and cout the symbol of the bigger number which is "A" at the first process and keep subtracting smaller from bigger till the end. what i want is cout-ing "." before "A" and 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;
}
Upvotes: 0
Views: 94
Reputation: 9619
Keep a int count
variable. Increment ++count
at every process, and print whatever you want when count
becomes 8.
Something like this:
int main()
{
int A=26;
int B=7;
char bigger='.'; //I suppose this is what you want to 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 it back to 0
}
}
cout<<endl;
getchar();
return 0;
}
Upvotes: 1