Splitting Vectors and counting inputs

I have an assignment where we have to input this sample code and get the following results:
----------
./lab3
Please enter the vectors here:
1 2 3 4 2 s
You are not giving even number of inputs!

./lab3
Please enter the vectors here:
1 2 3 2 4 4 s
The sample values are:
1 2 3
The frequencies are:
2 4 4
The discrete probability distribution is:
0.2 0.4 0.4
The mean is 2.2.
The variance is 0.56.
-----------

I got the part with the mean, variance , and probability distribution but i cannot split up user input into vectors for sample values and frequencies.

"1 2 3" are suppose to become sample values and "2 4 4" are suppose to become the frequencies.

------------
------------

I also wanted to know how to properly make the code so if there is an odd number of inputs the code outputs "You are not giving even number of inputs!". But if is an even number of inputs the code runs. To do this I have:

int main(int argc, char** argv){

float input = 1.0;

cout<<"Please enter vectors here:"

cin>>input;

// This states if size of vector is odd code does not run.
if (size(input % 2 != 0)){
cout<<"You are not giving even number of inputs!"
break;
}

//If size of vector is even then the code runs
else{
//rest of code
}

-------------
-------------
This is due tonight, 2/5/15 by 11:59 EST. Any help on how to properly do this is appreciated. Thank you.

Hint: input all the values into one vector and then look at the vector later.
i know to do that but i am unsure on how to look at the vector later
hint: use random function and generate the index/iterator of the vector which help to select sample value.

?? how to calculate frequency.

number of repetition of a specific value.
Last edited on
Topic archived. No new replies allowed.