Wrong output

Sorry my program keeps on giving wrong output someone please if know anything wrong.
Example I put

2
1 3
2 5

The first line is number of inputs
The following line is the cell and maximum units which can be in cell.
The program should find how many total cells remain to reach maximum units.

It output 4195501 instead of 5.

1
2
3
4
5
6
7
8
9
10
11
12
13
14

#include<iostream>
using namespace std;
int main(){
  int n,cell,max,ans;
  
  cin>>n;
  for(int i=0; i<n; i++){
    cin>>cell>>max;
    ans+=max-cell;
  }
  cout<<ans;
}
What value does ans have to begin with? I see you create ans on line 5, but what value does it have when you create it?
Zero
That is not true.
Oh thanks it worked
I declared ans like this
 
int ans=0;
Topic archived. No new replies allowed.