943,884 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 882
  • C++ RSS
Mar 10th, 2008
0

How???

Expand Post »
How to count> Is true I do this programming?

C++ Syntax (Toggle Plain Text)
  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. }
Reputation Points: 9
Solved Threads: 0
Posting Whiz in Training
nurulshidanoni is offline Offline
219 posts
since Nov 2007
Mar 10th, 2008
0

Re: How???

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,952 posts
since Aug 2005
Mar 11th, 2008
0

Re: How???

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

c++ Syntax (Toggle Plain Text)
  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. }
Reputation Points: 9
Solved Threads: 0
Posting Whiz in Training
nurulshidanoni is offline Offline
219 posts
since Nov 2007
Mar 11th, 2008
0

Re: How???

You should increment count only inside the second if statement.
Reputation Points: 769
Solved Threads: 128
Banned
ithelp is offline Offline
1,910 posts
since May 2006
Mar 11th, 2008
0

Re: How???

Is it true to make a condition statement? &&

C++ Syntax (Toggle Plain Text)
  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";
Reputation Points: 9
Solved Threads: 0
Posting Whiz in Training
nurulshidanoni is offline Offline
219 posts
since Nov 2007
Mar 12th, 2008
0

Re: How???

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

also you can use
C++ Syntax (Toggle Plain Text)
  1. cout << "\n\n";
instead of
C++ Syntax (Toggle Plain Text)
  1. cout << "\n";
  2. cout << "\n";
Reputation Points: 8
Solved Threads: 4
Light Poster
Necrolis is offline Offline
36 posts
since Jun 2007
Mar 12th, 2008
0

Re: How???

Is it true to make a condition statement? &&

C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 46
Solved Threads: 24
Posting Whiz in Training
hammerhead is offline Offline
248 posts
since May 2006
Mar 12th, 2008
0

Re: How???

Click to Expand / Collapse  Quote originally posted by hammerhead ...
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).
Reputation Points: 8
Solved Threads: 4
Light Poster
Necrolis is offline Offline
36 posts
since Jun 2007
Mar 12th, 2008
0

Re: How???

^ Sorry my fault.
Reputation Points: 46
Solved Threads: 24
Posting Whiz in Training
hammerhead is offline Offline
248 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Average of Numbers
Next Thread in C++ Forum Timeline: C++ Program Connect 4





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC