something not working help
#include <iostream> #include<time.h> using namespace std; void main() { setlocale(LC_ALL, "ukr"); srand(time(NULL)); const int n = 15; bool change = true; int arr[n], m = 0,p=0; for (int i = 0; i < n; i++) { arr[i] = rand() % 10 - 5; cout << arr[i] << " "; } cout << endl; for (int i = 0; i < n; i++) { if (arr[i] >= 0) { m += arr[i]; } else { p = m; m = 0; } } if (p > m) cout << endl << p << endl; else cout << endl << m << endl; }
else { p = m; m = 0; }blockelse { p = m; m = 0; }else { p = m; m = 0; }else { p = m; m = 0; }here it is necessary to check what is more and only then assign. - pavel