How do I make this C++ code into a function?

what I'm trying to do is put make 1 function that declares the array (Which I think I got) and the other function to print the array. The code works perfectly right now how it is but I am trying to practice on how to do them while using functions. Can someone help me out? Thanks


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
using namespace std; 

//Function Prototypes
void ArrayInt(double&);
void printUser();




int main(){

double alpha[50]; 

//Call Function
ArrayInt(alpha[50]);

//Start for loop
    for ( int i = 0; i < 50; i++ ){

            //Start if then statement
            //first 25 is the square of the index variable 'i'
            if (i < 25){
               alpha[i] = i*i;  
            }
            else{
                alpha[i] = 3 * i; 
            }
    } //end for loop

    //Start for loop
    for (int i = 0; i <50; i++){



        //Start if then statement
        if ( (i+1) % 10 == 0 ){  //10 numbers per line
            cout << endl; 
        } //end if
    } //end for loop

    system ("pause");
    return 0;
  }


void arrayInt(double& ){

    //Delcare and Initialize Array
    double alpha[50]; 
}

void printUser(){

    //Output to user
    cout << alpha[i] << " ";

}
Actually the code doesn't work perfectly, I have to erase the void printUser() function for it to work perfectly but I still need help on how to build those functions :)
Topic archived. No new replies allowed.