I set the variable biggest
to 0 and then looped every element in the array and checked if it is bigger than the current biggest
value and it works with regular numbers but not with negative ones.
How can I fix it to work with negatives too?
#include <iostream>
using namespace std;
int main(){
int a[7] = { -1, -3, -4, -5, -6, -1, -7 }; //array
int biggest = 0; //biggest number in the array
for(int i = 0; i < 4; i++) { //looping every element in the array
if(a[i] > biggest) { //checking if the current number is bigger then the biiger number
biggest = a[i]; //setting the biggest number to be = to the current number
}
}
cout << biggest << endl; //printing the biggest number
}