looping menu with some functions for array

help me to fix this, where do i wrong ? thanks before
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
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <array>

using namespace std;
void avg(array<int*,N>);
void max(array<int*,N>);
void min(array<int*,N>);
int main (int argc, char *argv[]) {
array<int, N> x = {10,12,13,14,15,16,17,18,19,20};
int l;
do {
cout << "1. Rerata " <<endl;
cout << "2. Maksimum "<< endl;
cout << "3. Minimum " << endl;
cout << "4. Keluar " <<endl;
cout << "masukkan pilihan : " << endl;
cin >> l;
if ( l == '1') {
avg (&x);
cout << "rerata : " << x << endl;
} else if ( l == '2') {
max(&x);
cout << "maksimum : " << x << endl;
} else if (l == '3') {
min(&x);
cout << "minimum : " << x << endl;
}
} while (l != '4');
cout << "anda telah keluar dari program" << endl;
}
void avg(array<int*,N> z){
int N = z.size();
int xsum =0;
for (int i =0; i < N; i ++) {
xsum = xsum + *z[i];
}
double x = xsum /10;
}
void max(array<int*, N> z) {
int N = z.size();
int x = *z[0];
for(int i =0; i< 10; i++) {
if (x < *z[i]) {
x = *z[i];
}
}
}
void min(array<int*,N> z) {
int N = z.size();
int x = 0;
for (int i =0; i < 10; i++) {
if (x > *z[i]) {
x = *z[i];
}
}
What problems are you seeing?
all of the function in (void) scope didnt want to process data
What do you mean, "didn't want to process data"? Can you please explain what behaviour you're seeing, and how it differs from the behaviour you expect to see. Being vague about your problems won't help anyone to help you.

I'm surprised this code even compiles. You've declared x to be an array of int, but your functions are defined to take an array of int*. Furthermore, in your function calls on lines 21, 24, 27, you're actually passing in a pointer to the array, whereas your functions are defined to take the array itself (by value).

Does your compiler not give you an error about those function calls?

Also, your avg, min and max functions don't return any values to the calling code.

Also, it would help you a lot if you'd adopt a sensible indentation style. That well help you see the flow of control through your code much more easily, helping you spot errors. It will help anyone else looking at your code, too.

A bit of whitespace between your function definitions would help, too.
Last edited on
Topic archived. No new replies allowed.