Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
c++ looping through a array test condition (10 points)?
void IntegerSet::printSet()
{
int i, count=0;
for(i=0;i<SIZE;i++)
if(a[i]==1)
{
count++;
cout<<i<<" ";
}
if(count==0)
cout<<"---";
}
I need to add some code to the print function I have defined so that only 20 elements show up on each line...... I understand I need something like if count = 20 cout<<endl; but by adding an if in the middle, it does nothing.... this condition I got now works great, prints everything as expected, just need a little assistance thanks........
Ive tried to add this to the end but it does nothing
if (count==19){
cout<<endl;
count ++;}
2 Answers
- oopsLv 61 decade agoFavorite Answer
for(int i=0; i<SIZE; i++)
{
if(a[i]==1)
{
if(count % 20 == 0)
cout << endl;
count++;
cout << i << " ";
}
}
- 1 decade ago
All you need is "only 20 elements show up on each line"?
So did you put
if (count==20)
{
cout<<endl;
count ++;
}
and
if(a[i]==1)
{
count++;
cout<<i<<" ";
}
into this { } right after for(i=0;i<SIZE;i++) ?
That is what i understand tho.
Good luck!