Help with a programm

So i started recently and i need some explanation on this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  #include <iostream>
using namespace std;
int main()

{int N,I,SUM,NUM;
float AVG;

 cout<<"N=";
 cin>>N;
 SUM=0;
 
 for (I=1;I<=N;I++)
    {cout<<"NUM=";
    cin>>NUM;
    SUM=SUM+NUM;
    }
    
 if (N>0)   
   {
   AVG=SUM/N;
   cout<<"AVERAGE IS "<<AVG;
   }
   else cout<<"THERE IS NO AVERAGE";
   
return (0);   
}.
well let's say i use 1,2,3,4 as numbers .the average the programm gives me is 2 which is wrong whereas if i move N or SUM or both into float it gives me the correct result 2,5 .shouldn't it give me 2,5 even if i use it is i have written it since AVG is on float ?
in the division SUM/N both variables are of type int.
That means integer divide is done, giving an integer result. After that, the result is assigned to AVG.
k understood .thx
Topic archived. No new replies allowed.