How to count> Is true I do this programming?

{
int count;
count=0;
count++;
 for ( int i = 0 ; i < students.size (); i++ )
{
for ( int k = 0;k<students.at(i).examcode.size(); k++ )
{
if (students.at (i).examcode.at(0)=0)
{
cout<<count++<< " ";
}
}
}
}

What are you trying to count? Number of examcodes for each student?

line 10: you want to use the == operator there, not the assignment = operator.

I want to count how many (3,13) appear..is it like this?

{
int count;
count=0;
count++;
for ( int i = 0 ; i < students.size (); i++ )
{
{
for ( int k = 1;k<students.at(i).examcode.size(); k++ )
if (students.at (i).examcode.at(0)==3)	
{
cout<<"  "<< count++;
}
if (students.at (i).examcode.at(k)==13)	
{
cout<< " " <<count++;
}
}
}
cout <<"\n";
}

Is it true to make a condition statement? &&

int count;
count++;
for ( int i = 0 ; i < students.size (); i++ )
{
for ( int k = 1;k<students.at(i).examcode.size(); k++ )
{
if (students.at (i).examcode.at(0)==1 && students.at (i).examcode.at(k)==1)	
{
count++;
}
}
}
cout<<"(1,1)="<<count;
cout <<"\n";
cout <<"\n";

yes that would work, thought you don't need to bracket a single statement under an if() ie

if(1 == 1)
{
     return true;
}

is the same as

if(1 == 1)
   return true;

you only need curly brackets if more than one piece needs execution

if(1 == 1)
{
    cout << "One does equal one";
    return true;
}

also you can use

cout << "\n\n";

instead of

cout << "\n";
cout << "\n";

Is it true to make a condition statement? &&

int count;
count++;
for ( int i = 0 ; i < students.size (); i++ )
{
for ( int k = 1;k<students.at(i).examcode.size(); k++ )
{
if (students.at (i).examcode.at(0)==1 && students.at (i).examcode.at(k)==1)	
{
count++;
}
}
}
cout<<"(1,1)="<<count;
cout <<"\n";
cout <<"\n";

That will not work. You have to increment count only inside the second if like ithelp said. Also initialize count to 0 in line 2.

That will not work. You have to increment count only inside the second if like ithelp said. Also initialize count to 0 in line 2.

there is no second if statement in the second lot of code, if he uses the current double conditional it should work fine(if count is properly init'ed to 0 as you said).

This article has been dead for over six months. Start a new discussion instead.