The Lead Game - Where am I going wrong?

 

#include   
 using namespace std;  
 int main()  
 {  
      int score1, score2, cumlead1=0, cumlead2=0, cumleadmax, winner, rounds, counter;  
      cin>>rounds;  
      for(counter=1; counter<=rounds; counter++)  
      {  
           cin>>score1>>score2;  
           cumlead1+=(score1-score2);  
           cumlead2+=(score2-score1);  
           if (cumlead1>cumleadmax)  
           {  
                cumleadmax=cumlead1;  
                winner=1;  
           }  
           else if (cumlead2>cumleadmax)  
           {  
                cumleadmax=cumlead2;  
                winner=2;  
           }  
      }  
      cout<<winner<<" "<<cumleadmax;  
      return 0;  
 }  

```

Initialize ‘cumleadmax’ to zero and it will run like magic :slight_smile:

2 Likes

Cumlead max isn’t initialized with any value…So it may cause an error…please do initialize a score for for it :slight_smile:

1 Like

Initializing cumleadmax fixed the problem. Thank you. :slight_smile:

1 Like
//