954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How???

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++<< " ";
}
}
}
}
nurulshidanoni
Posting Whiz in Training
219 posts since Nov 2007
Reputation Points: 9
Solved Threads: 0
 

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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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";
}
nurulshidanoni
Posting Whiz in Training
219 posts since Nov 2007
Reputation Points: 9
Solved Threads: 0
 

You should increment count only inside the second if statement.

ithelp
Nearly a Posting Maven
Banned
2,230 posts since May 2006
Reputation Points: 769
Solved Threads: 128
 

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";
nurulshidanoni
Posting Whiz in Training
219 posts since Nov 2007
Reputation Points: 9
Solved Threads: 0
 

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";
Necrolis
Light Poster
36 posts since Jun 2007
Reputation Points: 8
Solved Threads: 4
 

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.

hammerhead
Posting Whiz in Training
257 posts since May 2006
Reputation Points: 46
Solved Threads: 24
 
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).

Necrolis
Light Poster
36 posts since Jun 2007
Reputation Points: 8
Solved Threads: 4
 

^ Sorry my fault.

hammerhead
Posting Whiz in Training
257 posts since May 2006
Reputation Points: 46
Solved Threads: 24
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You