avarge value

I want the program to sum all numbers over 100 and sum all numbers below 100 that the user type in.
And then calculate a avarage value of each sum.

But how?

Maybe the program can be written more simple?

{
const int max_antal = 500;
int f[max_antal], k = 100, tal, antal=0;

cout << "Skriv in ett antal heltal" << endl;
while (cin>>tal)
f[antal++]=tal;

int n1, n2;
n1=0; // undre gräns
n2=antal-1; // övre gräns
while (n1 < n2)
{
// leta reda på första tal som är för stort i den vänstra gruppen
while (n1<n2 && f[n1]<=k)
n1++;
// leta reda på första tal som är för litet i den högra gruppen
while (n1<n2 && f[n2]>k)
n2--;
if (n1<n2)
{ // byt plats på f[n1] och f[n2]
tal=f[n1]; f[n1]=f[n2]; f[n2]=tal;
}
}
cout << "talen uppordnade" << endl;
for (int j=0; j<antal; j++)
cout << f[j] << endl;
}
Last edited on
the program is in german, right? it really doesnt matter, its just curiosity :D

u want the program to separate the numbers below 100 from the numbers above 100, the sum and get the average value?
Hehe, no it´s actually swedish.. yeah but I don´t know how I should do.. since there is not a limit of how many digit i can enter..

Someone have an idea?
the thing is that you will have to set a determined amount of variables, the user wont be able to sum 5 numbers or 20 numbers with the same program :S
I think I need to write a new program. But I want the program to know how many numbers I have typed... ? And then calcule the values based on how many numbers there are. Could I do something like; all numbers above 100 is transfered into one "field" and the numbers below ends in another "field"? And that the program knows how many numbers it puts in each field... maybe

the thing is that you have to set the quantity of numbers before using the program!! the program can't count numbers, because u'r the one who has to set the quantity.

Whay you can do is something like this, create 5 variables for each group:

1
2
3
int A,B,C,D,E;
int F,G,H,I,J;
int X;


then ask for a number

cin>>X

then something like this

1
2
if(X<=100) A=X;
else F=X;


It's a longshot, but it might work
Last edited on
Something like this maybe

Pseudo Code:

1. use a vector to input the numbers
2. Use a loop with an if statement with
2a. If vector[i] > 100, over100sum =+ and countOver100++
2b. Else under100sum =+ and countUnder100++

Display over100sum and divide over100sum by countOver100
same for under
Topic archived. No new replies allowed.