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 :/
#include <iostream>
#include <stdio.h>
usingnamespace 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;
}