Witam byłby ktoś w stanie wytłumaczyć mi co jest nie tak w tym kodzie że nie wyświetla on liczby najbliższej średniej(już kiedyś założyłem podobny temat ale z tego co pamiętam ze problemem nie za bardzo sb poradziłem :P, wtedy używałem fukdji fabs() tutaj na razie nie chcę jej wykorzystywać)
http://pl.spoj.com/problems/PP0604A/
EDIT:
Nowy kod źródłowy- zrobiłem kilka testów i na moim kompilatorze działa wszystko poprawnie, niestety spoj nie akceptuje zadania prosze o ewentualną podpoiwiedź :P
#include<iostream>
using namespace std;
int main()
{
int najblizszy(0);
int howMuch_Tests;
cout<<"Wpisz liczbe testow"<<endl;
cin>>howMuch_Tests;//wpisuje liczbe testów
for (int j=1;j<=howMuch_Tests;j++)
{
double nearestNumber_copy=0;
double nearestNumber=0;
double allNumbers=0;//Przechowuje wszystkie liczby
int ammount=0;
double average=0;
int table[100];
int howMuch_Numbers;
cout<<"Ile liczb ma byc w tabeli"<<endl;
cin>>howMuch_Numbers;
for (int k=0;k<=howMuch_Numbers;k++)
{
cin>>table[k];
++allNumbers;
ammount+=table[k];
}
average=ammount/allNumbers;
cout<<"Srednia !!!!!!!"<<average<<endl;
//cout<<ammount<<endl;
//cout<<allNumbers<<endl;
for(int i=0;i<=howMuch_Numbers;i++)
{
if (table[i]<average)
{
nearestNumber_copy=average-table[i];
if (nearestNumber==0 or nearestNumber>nearestNumber_copy)
{
nearestNumber=nearestNumber_copy;
if(nearestNumber=nearestNumber_copy)
{
najblizszy=table[i];
}
}
}
else if (table[i]==average)
{
najblizszy=table[i];
}
else if (table[i]>average)
{
nearestNumber_copy=table[i]-average;//3.2-3=0.2
if (nearestNumber==0 or nearestNumber>nearestNumber_copy)
{
nearestNumber=nearestNumber_copy;
if(nearestNumber=nearestNumber_copy)
{
najblizszy=table[i];
}
}
}
}
cout<<najblizszy<<endl;
}
return 0;
}