#include <iostream>
#include <ctime>
#include <cstdlib>
#include <algorithm> // std::random_shuffle
#include <iterator> // std::begin, std::end

int main()
{
    const int N = 5 ;
	std::srand( std::time(0) ) ;

    // the actual results are the five numbers at the beginning of the array
	int lottoresults[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } ;

	// generate 5 non-repeating numbers for lottoresults by
	// generating a random permutation of the elements in the array
	// and then picking the first five
	// see: http://e...content-available-to-author-only...e.com/w/cpp/algorithm/random_shuffle
	std::random_shuffle( std::begin(lottoresults), std::end(lottoresults) ) ;

	// or: std::random_shuffle( lottoresults, lottoresults+10 ) ; // legacy C++

	// print them out
	std::cout << "lotto winning numbers: " ;
	for( int i = 0 ; i < N ; ++i ) std::cout << lottoresults[i] << ' ' ;
    std::cout << '\n' ;

    // numbers entered by the user
    int userinput[N] = { 5, 9, 0, 8, 1 } ; // say, as an examplew
	std::cout << "user input: " ;
	for( int i = 0 ; i < N ; ++i ) std::cout << userinput[i] << ' ' ;
    std::cout << '\n' ;

    // check for matching numbers
    int cnt_matches = 0 ; // #matches

    std::cout << "matching numbers: " ;
    for( int i = 0 ; i < N ; ++i ) // for each number entered by the user
    {
        const int user_num = userinput[i] ;

        // check if the number number entered by the user is a winning number
        // (could use std::find() instead of writing a loop of out own)
        for( int j = 0 ; j < N ; ++j ) // for each winning number
        {
            if( user_num == lottoresults[j] ) // is it the same as user_num?
            {
                // yes, we got a match
                ++cnt_matches ;
                std::cout << user_num << ' ' ;
            }
        }
    }

    std::cout << "\nnumber of matches: " << cnt_matches << '\n' ;
}
