How???

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2007
Posts: 219
Reputation: nurulshidanoni is an unknown quantity at this point 
Solved Threads: 0
nurulshidanoni's Avatar
nurulshidanoni nurulshidanoni is offline Offline
Posting Whiz in Training

How???

 
0
  #1
Mar 10th, 2008
How to count> Is true I do this programming?

  1.  
  2. {
  3. int count;
  4. count=0;
  5. count++;
  6. for ( int i = 0 ; i < students.size (); i++ )
  7. {
  8. for ( int k = 0;k<students.at(i).examcode.size(); k++ )
  9. {
  10. if (students.at (i).examcode.at(0)=0)
  11. {
  12. cout<<count++<< " ";
  13. }
  14. }
  15. }
  16. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,660
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1500
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: How???

 
0
  #2
Mar 10th, 2008
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.
Last edited by Ancient Dragon; Mar 10th, 2008 at 11:31 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 219
Reputation: nurulshidanoni is an unknown quantity at this point 
Solved Threads: 0
nurulshidanoni's Avatar
nurulshidanoni nurulshidanoni is offline Offline
Posting Whiz in Training

Re: How???

 
0
  #3
Mar 11th, 2008
I want to count how many (3,13) appear..is it like this?

  1. {
  2. int count;
  3. count=0;
  4. count++;
  5. for ( int i = 0 ; i < students.size (); i++ )
  6. {
  7. {
  8. for ( int k = 1;k<students.at(i).examcode.size(); k++ )
  9. if (students.at (i).examcode.at(0)==3)
  10. {
  11. cout<<" "<< count++;
  12. }
  13. if (students.at (i).examcode.at(k)==13)
  14. {
  15. cout<< " " <<count++;
  16. }
  17. }
  18. }
  19. cout <<"\n";
  20. }
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,861
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 120
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

Re: How???

 
0
  #4
Mar 11th, 2008
You should increment count only inside the second if statement.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 219
Reputation: nurulshidanoni is an unknown quantity at this point 
Solved Threads: 0
nurulshidanoni's Avatar
nurulshidanoni nurulshidanoni is offline Offline
Posting Whiz in Training

Re: How???

 
0
  #5
Mar 11th, 2008
Is it true to make a condition statement? &&

  1. int count;
  2. count++;
  3. for ( int i = 0 ; i < students.size (); i++ )
  4. {
  5. for ( int k = 1;k<students.at(i).examcode.size(); k++ )
  6. {
  7. if (students.at (i).examcode.at(0)==1 && students.at (i).examcode.at(k)==1)
  8. {
  9. count++;
  10. }
  11. }
  12. }
  13. cout<<"(1,1)="<<count;
  14. cout <<"\n";
  15. cout <<"\n";
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 36
Reputation: Necrolis is an unknown quantity at this point 
Solved Threads: 4
Necrolis's Avatar
Necrolis Necrolis is offline Offline
Light Poster

Re: How???

 
0
  #6
Mar 12th, 2008
yes that would work, thought you don't need to bracket a single statement under an if() ie
  1. if(1 == 1)
  2. {
  3. return true;
  4. }
is the same as
  1. if(1 == 1)
  2. return true;
you only need curly brackets if more than one piece needs execution
  1. if(1 == 1)
  2. {
  3. cout << "One does equal one";
  4. return true;
  5. }

also you can use
  1. cout << "\n\n";
instead of
  1. cout << "\n";
  2. cout << "\n";
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 248
Reputation: hammerhead is an unknown quantity at this point 
Solved Threads: 24
hammerhead's Avatar
hammerhead hammerhead is offline Offline
Posting Whiz in Training

Re: How???

 
0
  #7
Mar 12th, 2008
Originally Posted by nurulshidanoni View Post
Is it true to make a condition statement? &&

  1. int count;
  2. count++;
  3. for ( int i = 0 ; i < students.size (); i++ )
  4. {
  5. for ( int k = 1;k<students.at(i).examcode.size(); k++ )
  6. {
  7. if (students.at (i).examcode.at(0)==1 && students.at (i).examcode.at(k)==1)
  8. {
  9. count++;
  10. }
  11. }
  12. }
  13. cout<<"(1,1)="<<count;
  14. cout <<"\n";
  15. 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.
Last edited by hammerhead; Mar 12th, 2008 at 9:46 am.
There are 10 types of people in the world, those who understand binary and those who don't.

All generalizations are wrong. Even this one.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 36
Reputation: Necrolis is an unknown quantity at this point 
Solved Threads: 4
Necrolis's Avatar
Necrolis Necrolis is offline Offline
Light Poster

Re: How???

 
0
  #8
Mar 12th, 2008
Originally Posted by hammerhead View Post
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).
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 248
Reputation: hammerhead is an unknown quantity at this point 
Solved Threads: 24
hammerhead's Avatar
hammerhead hammerhead is offline Offline
Posting Whiz in Training

Re: How???

 
0
  #9
Mar 12th, 2008
^ Sorry my fault.
There are 10 types of people in the world, those who understand binary and those who don't.

All generalizations are wrong. Even this one.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum


Views: 769 | Replies: 8
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC