mercredi 3 août 2016

Array is not summing and Displaying random numbers

#include "stdafx.h"
#include <iostream>

    using namespace std;
//  ====================

//  ==========================
    const unsigned int MIN_VALUE = 0;
    const unsigned int MAX_VALUE = 4;
    const int N = 4;
//  ================

//  ===================
//  Function Prototypes
//  ===================

//      ========================================
        void IntilizeGenerator(unsigned int a[]);
        int RandomNumber();
        int SumArray(int a[], int& sum);
        void Output(int a[], int sum);
//      ==============================

//   ============
     int main() {

         int sum;
         int num[N];

         num[N-1] = RandomNumber();
         sum = SumArray(num, sum);
         Output(num, sum);


         cout << endl; 
         return 0;
    }// Function Main()
//  ===================

//  ======================================
     void IntilizeGenerator(unsigned int a[]) {
         srand(a[N]);

     }// Function IntilizeGenerator()
//   ================================

//   =======================
     int SumArray(int a[], int& sum) {

        sum = 0;
        int ii = 0;

        while (ii < N) {
            sum += a[ii];
            ii++;
        }

        return sum;

     }// Function SumArray()
//   =======================    

//   ====================
     int RandomNumber() {

         return MIN_VALUE + rand() % (MAX_VALUE - MIN_VALUE + 1);
     }// Function RandomNumber()
//   ===========================

     void Output(int a[], int sum) {

         cout << "The array contains about " << N << endl;
         cout << "The array has these values " << a[N] << endl;
         cout << "The sum of these numbers are " << sum << endl; 

     }// Function Output()
//   =====================

So the Problem I ma having is that I pass my randomNumber function into my array and it won't generate the random numbers which in turn won't add them up in the program. I am still trying to understand the random number generator as well so any advice on that will be most appreciated!




Aucun commentaire:

Enregistrer un commentaire