arrays and functions final

Okay this is my final assignment for my coding class, i know how to do mostly everything but the functions i hate so much, and everything i know needs to be collab with the functions, please help.
Instructions:
1. 2 function prototypes, one that counts in multiples (must be a void or contain cout statements, accepts 2 parameters, and uses a for loop to display the multiples of the numbers input) and another that calculates the average of grades entered (must return the value, must have 2 parameters) == this is really whats killing me
2. Must have a sentinel controlled while loop to quit, (Never taught us this, apparently we were suppose to "Go along with it"
3. Switch statement for the choice, a for average, q is quit, and m is multiples, (i got this)
4. Array that includes a for loop to input grades, it is in the switch statement, he said you can hard code the size of array and then calculate the sum in the loop, and must pass the sum and number of grades to the average function "you can hard code number of grades parameter, but use a variable for sum parameter"
5. Store the return value from the average function inside the switch case and display the average in the switch case.
6. Have an in and else statement anywhere in the program

- I know its a crap ton but I'm really lost with mixing arrays and functions, i will very much appreicate tips and help with that


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
59
60
61
62
63
64
65
66
 #include <iostream>
#include <string>
using namespace std;
int choice;
int countby;
void m(char choice); 
{
    double number, double result, int countup, int countby;
    for(int i=0; i == countup; i++)
        {
            cout << countby + countby;
        }
}
int main()
{
    char response;
    char choice;
    char m;
    char q;
    char a;
    int countup;
    int countby;
    for(;;)
    {
    cout << "Enter a choice or q to quit:  " << endl;
    cout << "Enter 'm' to count in multipless:  " << endl;
    cout << "Enter 'a' to get the average of the bottom 4 and top 4 grades in this class:  ";
    
    cin >> choice;
    
    switch(choice)
    {
    case 'q':
            {
                cout << "Goodbye!" << endl;
                break;
            }
    case 'm':
        {
            cout << "Enter a number to count up to:  " << endl;
                cin >> countup;
                cout << "Enter a number to count by:  " << endl;
                cin >> countby;
        }
        
    case 'a':
        {
            cout << "Enter the bottom 4 grades and the top 4 grades:  " << endl;
            for(int i=0; i<8;i++)
                {
                    cout << "Enter Grade 1";
                }
                
        }
        
        default
        {
            cout << "Existing" << endl;
            break;
        }
    }
    }    
     cin >> response;
     return 0; // end the program with a sentinel loop, again have no idea how 
}
Also I'm confused on how to find the average of the grades, so help on that please "case a "
Does this help get you started?
You know how to calculate an average in general?

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
#include <iostream>

void sumFunction(int arrayLen, const int *array);
void countsInMultiples(int countValue, int howLongToCount);
using namespace std;

int main() {
    countsInMultiples (3, 10);
    int arrayLen = 6;
    int array[arrayLen] = {0, 1, 3, 2, 4, 5};
    sumFunction (arrayLen, array);
    return 0;
}

void countsInMultiples(int countValue, int howLongToCount) {
    for (int i = 0; i < howLongToCount; i++) {
        cout << countValue * i << endl;
    }
}

void sumFunction(int arrayLen, const int *array) {
    int sum = 0;
    for (int i = 0; i < arrayLen; i++) {
        cout << sum << " + " << array[i] << " = ";
        sum += array[i];
        cout << sum << endl;
    }
}


0
3
6
9
12
15
18
21
24
27
0 + 0 = 0
0 + 1 = 1
1 + 3 = 4
4 + 2 = 6
6 + 4 = 10
10 + 5 = 15

Process finished with exit code 0


Last edited on
@bardo99:

I'm posting this here, in case you're not still checking your last thread. Please DON'T delete your question after you've received an answer. It ruins this thread as a learning resource for others. It's a selfish abuse of this forum, and of the people who've taken the time and effort to answer your question.

Below is a complete quote of the original question asked in this thread, in case you decide to do the same thing here:


Okay this is my final assignment for my coding class, i know how to do mostly everything but the functions i hate so much, and everything i know needs to be collab with the functions, please help.
Instructions:
1. 2 function prototypes, one that counts in multiples (must be a void or contain cout statements, accepts 2 parameters, and uses a for loop to display the multiples of the numbers input) and another that calculates the average of grades entered (must return the value, must have 2 parameters) == this is really whats killing me
2. Must have a sentinel controlled while loop to quit, (Never taught us this, apparently we were suppose to "Go along with it"
3. Switch statement for the choice, a for average, q is quit, and m is multiples, (i got this)
4. Array that includes a for loop to input grades, it is in the switch statement, he said you can hard code the size of array and then calculate the sum in the loop, and must pass the sum and number of grades to the average function "you can hard code number of grades parameter, but use a variable for sum parameter"
5. Store the return value from the average function inside the switch case and display the average in the switch case.
6. Have an in and else statement anywhere in the program

- I know its a crap ton but I'm really lost with mixing arrays and functions, i will very much appreicate tips and help with that

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
59
60
61
62
63
64
65
 #include <iostream>
#include <string>
using namespace std;
int choice;
int countby;
void m(char choice); 
{
    double number, double result, int countup, int countby;
    for(int i=0; i == countup; i++)
        {
            cout << countby + countby;
        }
}
int main()
{
    char response;
    char choice;
    char m;
    char q;
    char a;
    int countup;
    int countby;
    for(;;)
    {
    cout << "Enter a choice or q to quit:  " << endl;
    cout << "Enter 'm' to count in multipless:  " << endl;
    cout << "Enter 'a' to get the average of the bottom 4 and top 4 grades in this class:  ";
    
    cin >> choice;
    
    switch(choice)
    {
    case 'q':
            {
                cout << "Goodbye!" << endl;
                break;
            }
    case 'm':
        {
            cout << "Enter a number to count up to:  " << endl;
                cin >> countup;
                cout << "Enter a number to count by:  " << endl;
                cin >> countby;
        }
        
    case 'a':
        {
            cout << "Enter the bottom 4 grades and the top 4 grades:  " << endl;
            for(int i=0; i<8;i++)
                {
                    cout << "Enter Grade 1";
                }
                
        }
        
        default
        {
            cout << "Existing" << endl;
            break;
        }
    }
    }    
     cin >> response;
     return 0; // end the program with a sentinel loop, again have no idea how 
}

Okay thank you and sorry i thought you were suppose to delete them after words and i didn't know how so i did that, but i will leave them up now
oh and your code was very helpful! can you explain how you use the sentinel loop to end a program? is it with a break statement? and also when you used the void functions, do you have to write them out twice like you did?
Topic archived. No new replies allowed.