| | |
How???
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
How to count> Is true I do this programming?
C++ Syntax (Toggle Plain Text)
{ 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.
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.
I want to count how many (3,13) appear..is it like this?
c++ Syntax (Toggle Plain Text)
{ 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"; }
You should increment count only inside the second if statement.
Is it true to make a condition statement? &&
C++ Syntax (Toggle Plain Text)
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
is the same as you only need curly brackets if more than one piece needs execution
also you can use
instead of
C++ Syntax (Toggle Plain Text)
if(1 == 1) { return true; }
C++ Syntax (Toggle Plain Text)
if(1 == 1) return true;
C++ Syntax (Toggle Plain Text)
if(1 == 1) { cout << "One does equal one"; return true; }
also you can use
C++ Syntax (Toggle Plain Text)
cout << "\n\n";
C++ Syntax (Toggle Plain Text)
cout << "\n"; cout << "\n";
Judgment is Final, Death is Eternal
Day of Death, Mod for Diablo II | The Phrozen Keep - D2Mods Central
Day of Death, Mod for Diablo II | The Phrozen Keep - D2Mods Central
•
•
•
•
Is it true to make a condition statement? &&
C++ Syntax (Toggle Plain Text)
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";
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.
All generalizations are wrong. Even this one.
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).
Judgment is Final, Death is Eternal
Day of Death, Mod for Diablo II | The Phrozen Keep - D2Mods Central
Day of Death, Mod for Diablo II | The Phrozen Keep - D2Mods Central
![]() |
Other Threads in the C++ Forum
- Previous Thread: Average of Numbers
- Next Thread: C++ Program Connect 4
Views: 769 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll dynamic encryption error file forms fstream function functions game givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort stream string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






