Array Function Help

So im doing some HW for my C++ class and im not sure how to do this.
Hes asking fot this:
A void function called getOptions()that is bool, with 7 parameters passed by reference.

But instead of passing the 7 parameter use an array thats is declared in main() and passed to the function.

The function asks the user to select options
As each option is prompted the user enters Y or N

Here how the output looks:

Moon Roof: y
Voice Integrated System: n 
Back up Cam: y


etc. for all seven options
Last edited on
Firstly, this is not a homework site, if you are stuck with one particular thing then ask. Secondly, have a go first and post code that doesn't work (using code tags) and thirdly "a void function called getOptions() this is bool". This sentence is semantically void. A function cannot be both void and bool.
I have a code but im pretty sure its completely wrong. Sorry for wasting your time ill just try to figure it out thanks though
Sorry if I was being a bit harsh, I didn't mean to. Let me just say you can pass arrays like anything else into a function void someFunction(bool array[7]) and for the rest of it you'll want to use cout to display the "Moon Roof" or "Voice Integrated System", which I presume will be in an array and cin to store whether or not someone typed y or n.
Last edited on
I have a code but im pretty sure its completely wrong.

We can't help you with it if we don't see your code. Don't worry about it being wrong. We will try and point out any errors and how you can improve the code. Don't worry about wasting our time, because we're here because we want to help.
you can pass arrays like anything else into a function void someFunction(bool array[7])

It's a bad habit to have a number between the []s when declaring an array parameter like void someFunction(bool array[7]) as they are ignored by the compiler (due to to array decay) and therefore have no meaning.

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
#include <iostream>
using namespace std;

// better to use arr[] or arr* as it makes it clearer
// that the function has no idea what size the array is!
void show(int arr[2], int actualSize) {
    cout << "arr = ";
    for(int i = 0; i < actualSize; ++i)
        cout << " " << arr[i];
    cout << "\n";
}

int main() {
    int var1[1] = {3};
    int var2[2] = {3,1};
    int var4[4] = {3,1,4,1};
    int var8[8] = {3,1,4,1,5,9,2,6};

    show(var1, 1);
    show(var2, 2);
    show(var4, 4);
    show(var8, 8);

    return 0;
}


arr =  3
arr =  3 1
arr =  3 1 4 1
arr =  3 1 4 1 5 9 2 6


Andy
Topic archived. No new replies allowed.