H
HS1
Hello all
I have a vector that store answer objects. Each object has a question number
and answer value that can be presented as following:
-----------------------------------------------
Question number |Answer
3 Y
5 N
8 Y
10 N
.... ..
3 Y
5 N
8 Y
10 N
.. ...
3 N
5 Y
8 Y
10 N
... ..
What I have to do is to determine how many percent answer is "Y" or "N" for
each question.
For example:
question 3: 13% yes and 87% no
question 5: 23% yes and 68% no
It can be seen that those objects are separated into groups and each has
same number of questions. I also have the list of question numbers (e.g: 3,
5, 8, 10...).
What is the best solution for this. Could you please help
Many thanks
SH1
--------------------------------------------------------------
I have this solution but it run many times through the vector of answer
objects
if (i=0; i<vector.size; i++){
int total_answer=0;
int yes =0;
double percent_3;
if (element(i).question_number = 3){
total = total+1;
if (element(i).value = yes) {
yes= yes+1;
}
}
percent = (double) yes/total;
......
}
if (j=0; j<vector.size; j++){
int total_answer=0;
int yes =0;
double percent_5;
if (element(i).question_number = 5){
total = total+1;
if (element(i).value = yes) {
yes= yes+1;
}
}
percent = (double) yes/total;
......
}
......
.....
I have a vector that store answer objects. Each object has a question number
and answer value that can be presented as following:
-----------------------------------------------
Question number |Answer
3 Y
5 N
8 Y
10 N
.... ..
3 Y
5 N
8 Y
10 N
.. ...
3 N
5 Y
8 Y
10 N
... ..
What I have to do is to determine how many percent answer is "Y" or "N" for
each question.
For example:
question 3: 13% yes and 87% no
question 5: 23% yes and 68% no
It can be seen that those objects are separated into groups and each has
same number of questions. I also have the list of question numbers (e.g: 3,
5, 8, 10...).
What is the best solution for this. Could you please help
Many thanks
SH1
--------------------------------------------------------------
I have this solution but it run many times through the vector of answer
objects
if (i=0; i<vector.size; i++){
int total_answer=0;
int yes =0;
double percent_3;
if (element(i).question_number = 3){
total = total+1;
if (element(i).value = yes) {
yes= yes+1;
}
}
percent = (double) yes/total;
......
}
if (j=0; j<vector.size; j++){
int total_answer=0;
int yes =0;
double percent_5;
if (element(i).question_number = 5){
total = total+1;
if (element(i).value = yes) {
yes= yes+1;
}
}
percent = (double) yes/total;
......
}
......
.....