Help please!

Hi everyone, first post here, you all seem really helpful.
I'm trying to write a program that allows a user to enter between 1 and 10 values into a 10 element array, (with the element values between 0 and 10) and calculate the average value in the array, using an averaging function.

PC asks user how many values they wish to average (between 1 and 10)
User: 4
PC, please enter your (4) values, use integers between 0 and 10
User: 2, 0, 5, 6
PC, your average is ...

with necessary statements to stop values outside the threshold being entered

Unfortunately my code got a little confused and my debugger is no longer working properly either :/

Please help

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


float average (float a, float b)  //function
{
  float r;
  r=a/b;
  return (r);
}

int main()
{
    float array[10];
    for (int i=0; i<10; i++)
    {
        array [i]=0;
    }

    int x;

 for ( int j=0; j<x; j++)
  {
    cout << "Please enter how many value(s) you wish to average, an integer value in the range 0-10: ";
    cin >> x;

  while (x>10 || x<1)
		{
			cout << "Please enter a value in the range 1-10, try again: ";
			cin >> x;
		}

    cin >> array[j];

  }

    int q, sum = 0 ;
 	for (q=0; q<10; q++)
	{
		sum+=array[q];
	}

    float s, out;

    s = sum;

    out = average(s, x);

    cout << "Your average is: " <<out;

    return 0;
}
closed account (Dy7SLyTq)
line 21: you need to give a value to x before using it in a loop
thanks, but still no luck
Last edited on
hold on, bit more shuffling round, seems to be getting there

all fixed. thank you very much
Last edited on
Topic archived. No new replies allowed.