### average count

Hello, want to write a code with average count.

program is supposed to count the average number, then put out the numbers that are below the average number. E.g: I insert 4, then I input 4 integers; 1 2 3 4 and it outputs 2, because the average number of 1 2 3 and 4 is 2.5 and there are 2 integers below 2.5

so here's my current code
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849`` ``````#include using namespace std; int main() { int number = 0; int tala = 0; int avrg = 0; int input = 0; int i = 0; cin >> input; int* arr = new int [input]; for(i = 0; i < input; i++) { cin >> tala; arr[i] = tala; number += tala; /*if(arr[i] == 0) { arr[i]++; } */ } avrg = number / tala; for(i = 0; i < input; i++) { arr[i] = tala; number = number / tala; if(tala < avrg) { tala++; } } cout << avrg << endl; }``````

any inputs?
nevermind I changed the int in to double and reversed tala = arr[i]
because I wanted to count the amount of numbers in the arr[i].

Got the correct output now.
Hi Ariamn,

I updated your code and it should work fine:
 ``123456789101112131415161718192021222324252627282930313233343536373839404142`` ``````#include using namespace std; int main() { float number = 0.0; // in case the user enters a decimal value float avrg; // You will need the decimal precision, doens't need to be declared here int input; //also doesn't need to be declared here cout << "Enter how many values you are going to use: " << endl; cin >> input; float* arr = new float [input]; // to allow the user to enter a decimal value cout << "Enter all the values consecutively: " << endl; for(int i = 0; i < input; i++) // Loop for user to enter in all the values { cin >> arr[i]; number += arr[i]; /*if(arr[i] == 0) { arr[i]++; } */ } avrg = number / input; for(int i = 0; i < input; i++) // Loops through arr[] and outputs if arr[i] is lower than avrg { if(arr[i] < avrg) { cout << "Under the average: " <

I made some changes however the comments should help you along the way, if you need any help feel free to PM me, good luck !
Topic archived. No new replies allowed.