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;
}
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. 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