Nov 16, 2012 at 3:32pm UTC
I need it to return the entire array from userNumbers function and store it in usernum array in main function.
**there are some blank functions right now because i didnt code there purpose yet, i need to figure out how to pass array for most of assignment**
Here is my code so far
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
//****************************************************************************
// Programmer:
//
// Description:
//*****************************************************************************
#include <iostream>
#include <fstream>
#include <iomanip>
void pickNumbers(int []);
int userNumbers(int []);
void checkNumbers();
void printWinnings();
using namespace std;
int main (){
int usernum [4];
for (int i=0; i<5; i++){
usernum [i]=userNumbers();// <==help here
}
int winnum [4];
cout << usernum[0]<< usernum[1] <<usernum[2]<<usernum[3]<<usernum[4];
return 0;
}
int userNumbers(int num1[]){
cout << "Please enter your lottery numbers seperated by spaces" ;
cin >> num1[0],num1[1],num1[2],num1[3],num1[4];
for (int i=0; i<5; i++){
return num1[i];
}}
void pickNumbers(int num[]){
}
void checkNumbers(){
}
void printWinnings(){
}
Last edited on Nov 16, 2012 at 3:39pm UTC
Nov 16, 2012 at 4:15pm UTC
1. You can't "return" a basic array. Arrays are evil and should be avoided at all costs, but I'm guessing you are required to use them for this. Instead of returning the array, pass the array as a pointer so the function can modify the existing array.
2. Your array has four elements, 0 to 3, but you are treating it like it has 5 elements, which can cause segfaults if you're lucky.
Nov 16, 2012 at 4:37pm UTC
use pointers like L B said, or use a vector.
Nov 16, 2012 at 6:41pm UTC
That line 14 is to die four.
Nov 16, 2012 at 7:06pm UTC
There will be 2 arrays, currently trying to get first one to work. each array will have 5 numbers.
when you say
int winnum [4];
does that mean there is 5 memory allocations 0-4 or is it total number of spots you need to reserve.
When you pass an array by default, does it make it editable by all functions, or temporarily editable until function is over?
Nov 16, 2012 at 7:56pm UTC
I meant it passes an array by reference as default, oops.
Nov 16, 2012 at 8:08pm UTC
jkfde wrote:when you say
int winnum [4 ];
does that mean there is 5 memory allocations 0-4 or is it total number of spots you need to reserve.
That means you have an array of
4 integers,with indices 0 to 3.
Last edited on Nov 16, 2012 at 8:09pm UTC