I have this data ROW 1: 3 15 36 56 71 83 97 106 118 135 138
ROW 2: 3 10 31 51 71 78 97 105 113 135 138

How to count when 3 meet 15 is 1
3 meet 36 is 1
3 56 is 1
3 meet 71 is 2
3 meet 138 is 2
and so on

ROW 1: 3 15 36 56 71 83 97 106 118 135 138

I get 3 meet 36 is count as 1
example, when row 12 etc have 3 14 36 71
then I must count 3 meet 36 is 2

So, I dont know how to count it....thats my problem

So in row 1 3 meet 138 is 9 because there are 9 numbers between those two values.
Lets assume we have those values in an array

int array[11] = {3, 15, 36, 56, 71, 83, 97, 106, 118, 135, 138};
int counter = 0;
int a = 3;
int b = 138;
int i;
// find first value in the array
for(i = 0; i < 11 && array[i] != a; ++i)
    ;
// now increment i until you find the value of [b]b[/b]
// and increment [b]count[/b] on each loop iteration
//
// solution for this is not shown -- don't want to spoil your homework :)

So in row 1 3 meet 138 is 9 because there are 9 numbers between those two values.

No..no like that...in row 1 3 meet 138 is 1 means how many times 3 meet 138.

and if in row 20 3 meet 138 again so I must count it 2

Let me guess. If this was the data:

1, 3, 5, 6, 11, 12, 14
4, 5, 8, 12, 13, 15
2, 3, 4, 6
1, 3, 7, 10, 12, 13
2, 3, 4, 6, 11, 56
1, 4, 10, 11, 15
2, 3, 4, 10, 11, 12

3 meet 11 would equal 3 since 3 and 11 are in the same row in three of the seven rows above (rows 1, 5, and 7).

Yessssssss..like that..my problem is..to count row by row how many 3 meet 11,3 meet 1,3 meet 2, 3 meet 4, 3 meet 5, 3 meet 6.....3 meet 139

You can't expect people to understand that you mean my "meet" when you do not define it. If you define a function between two numbers called "meet" and the definition of meet (a, b) is "the number of rows which contain both a and b", then you need to say that. You can't assume that people will know what you mean if you don't tell them. Now that we know what you mean by "meet", what exactly do you want the program to accomplish?

My objective is I want to how much the examcode.

Is it like this?

int mycount; 
int myints[] = {3,1}, {3,2},{3,3},{3,4}...;   
mycount = (int) count (myints, myints+2, 1);
cout << "1 appears " << mycount << " times.\n";

My objective is I want to how much the examcode.

Is it like this?

int mycount; 
int myints[] = {3,1}, {3,2},{3,3},{3,4}...;   
mycount = (int) count (myints, myints+2, 1);
cout << "1 appears " << mycount << " times.\n";

No, it is not like that. You are not declaring an array of integers in this line. It is an error:

int myints[] = {3,1}, {3,2},{3,3},{3,4}...;

In another thread's code you have a vector of integers in your struct:
http://www.daniweb.com/forums/thread110716.html

struct student
{
string studentid;
vector <int> examcode;
};

Given two integers you will need to decide whether both of those integers are in the vector of integers (called examcode). I suggest a boolean function. You could set up a function like this:

bool HasTakenBothExams (student stu, int exam1, int exam2)
{
  // implementation.  Return true if both exam1 and
  // exam2 are in stu.examcode vector, false otherwise
}

That will be your helper function. You also have a vector of type student called students (also in another thread. See link above). Given two exam codes, go through that vector of type student (called "students") and continually call the function above, once per individual student. You'll start a counter and initialize it to 0. If the above function returns true, increment the counter. Otherwise, do not. When you've gone through your entire vector of type student, the number of rows containing the two integer exam codes will be stored in your counter tally.

This code below is counter-productive. You took code that was never intended for your problem and tried to change it to code that fits your problem, and if you don't understand the original code, it will turn the tweaked code into jibberish, as this is:

int mycount; 
int myints[] = {3,1}, {3,2},{3,3},{3,4}...;   
mycount = (int) count (myints, myints+2, 1);
cout << "1 appears " << mycount << " times.\n";

Also, stop writing stuff like this if you want more help. As I have said before, what you are trying to do cannot be described in one sentence, particularly not this sentence:

My objective is I want to how much the examcode.

can I try to do like below programming to do a boolean function?

// function example
#include <iostream>
using namespace std;

int students (int exam1, int exam2)
{
  int r;
  r=exam1&exam2;
  r=1
  cout << "The result is " << r;
  return 0;
}

can I try to do like below programming to do a boolean function?

// function example
#include <iostream>
using namespace std;

int students (int exam1, int exam2)
{
  int r;
  r=exam1&exam2;
  r=1
  cout << "The result is " << r;
  return 0;
}

You're missing a semicolon on line 9. All this function does is display what is below regardless of what exam1 and exam2 are.

The result is 1

And what does this function have to do with a boolean function?

Do you have even the slightest idea of what you are doing?
line 8: performs bit-wise and operation on the two values,
line 9: toss the result set by line 8 straight into the bit bucket and set the value of r to 1.
So why don't you just delete line 8 because it's not used for anything.

If you remove all the fluf and unnecessary code, your function boils down to this:

// function example
#include <iostream>
using namespace std;

int students (int exam1, int exam2)
{
  cout << "The result is 1";
  return 0;
}
boolean function
bool HastakenBothExams (student stu, int exam1, int exam2)
 if (exam1 & exam2 )
{ 
cout <<"1"<<endl;// Return true if both exam1 and exam2 are in stu.examcode vector; false otherwise
else
}
    cout <<"0"<<endl;

That functions does not do what the comments on line 5 says. Doing a bit-wise and operation on two variables does not check to see if either of those values exist in the student class. You have to make comparisons

if( (stu.exam1 == esam1) && (stu.eam2 == exam2))
{
   return true;
}
else
{
   return false;
}

is it like this?

boolean function
bool HastakenBothExams (student stu, int exam1, int exam2)
if( (stu.exam1 == exam1) && (stu.exam2 == exam2))
{
return true;
cout << "Boolean operator tests (1 = true)\n";
}
else
{
return false;
cout << "Boolean operator tests (0 = false)\n"
}

you have missed a couple braces (at lines 2 and 13) and you have lines 5&6 and 10&11 backwards. (can't display something after the function returns).

also delete line 1, or make it a comment, because it does nothing.

How to correct it?
63.cpp
error C2143: syntax error : missing ')' before '.'[/B]
error C2059: syntax error : ')'
error C2181: illegal else without matching if
Error executing cl.exe.

63.exe - 3 error(s), 0 warning(s)

{
{		
bool HastakenBothExams (student, int exam1, int exam2);
if( (student.exam1 == exam1) && (student.exam2 == exam2) );
cout << "1" << endl;		
else 
 cout << "0" << endl;
}	
        return 0;
}

Or like this?

{		
		bool HastakenBothExams (student, int exam1, int exam2);
		{
			char answers;         //Stores user's answers
		do
		{   ( (student.exam1 == exam1) && (student.exam2 == exam2));
		cout << "1" << endl;		
		}
		while ( (student.exam1 != exam1) && (student.exam2 != exam2));
			cout << "0" << endl;
	}	
        return 0;

Neither of the functions you just posted make the slightest bit of sense and both are full of syntax errors. If you do not recognize why these functions don't compile, then the program you are trying to do is far too demanding for your current skill set. There is also a button with "Preview Post" written on it. It is located next to the "Submit Reply" button. Start using it. It shows what your post is going to look like before you submit the reply and gives you a chance to correct things. If you see:

code=C++]

in your preview, that means you left off a bracket. Preview your post, correct it, preview it again, then when it's right, hit the "Submit Reply" button.

{
bool HastakenBothExams (student, int exam1, int exam2);
{
char answers; //Stores user's answers
do
{ ( (student.exam1 == exam1) && (student.exam2 == exam2));
cout << "1" << endl;
}
while ( (student.exam1 != exam1) && (student.exam2 != exam2));
cout << "0" << endl;
}
return 0;

This code makes no sense. You have "student" all by itself in the parameter list. You can't have that. You have a bracket before the function starts and a "return 0" after the final bracket. You have a semicolon in line 2, you don't use the variable "answers", and you have a boolean function returning 0.

if( (student.exam1 == exam1) && (student.exam2 == exam2) );
{
   return true;
}
else
{
   return false;
}

I try to do like this..but error..how to correct it.?


syntax error : missing ')' before '.'
syntax error : ')'
error C2181: illegal else without matching if

if( (student.exam1 == exam1) && (student.exam2 == exam2) );
{
   return true;
}
else
{
   return false;
}

I try to do like this..but error..how to correct it.?


syntax error : missing ')' before '.'
syntax error : ')'
error C2181: illegal else without matching if

Look at your struct:

struct student
{
string studentid;
vector <int> examcode;
};

Do you see "exam1" or "exam2" in it? You also have a semicolon you need to get rid of in line 1. And you can't call your variable "student" since that is the name of the struct.

no i dont see,but how call exam1 and exam2?

If you want help, you are going to have to be more descriptive in your questions. I don't know what you are asking.

Or I must do like this???

{  int stu;
   if((stu.exam1 == exam1)&&(stu.exam2 == exam2))
 return true;
}
else
{
return false;
}

3 13 34 54 71 81 97 105 116 135 138


firsly, I would like to call exam1 which 3 and exam2 which 13.

How to call line 1 only? i<2 and j< 2?

for ( int i = 1 ; i < students.size (); i++ )
{
   cout <<i<<":\t" ;   // output student id
   for ( int j = 1;j<students.at(i).examcode.size(); j++ )
	   cout << students.at (i).examcode.at(j) <<"\t";   // output list of exam codes for this student
   cout<<""<<"\n";       
}
This question has already been answered. Start a new discussion instead.