Statistics are often calculated with varying amounts of input data. Write a program that takes any number of non-negative integers as input, and outputs the max and average. A negative integer ends the input and is not included in the statistics.
Ex: When the input is:
15 20 0 5 -1
the output is:
20 10
You can assume that at least one non-negative integer is input.
#include <iostream>
using namespace std;
int main() {
   int count = 0;
   int max = 0;
   int total = 0;
   int num;
   int avg;
   
   cin >> num;
   
   while (num >= 0) {
      count++;
      total += num;
      
      if (num > max){
         max = num;
      }
      cin >> num;
   }
   
   avg = total / count;
   cout << avg << " " << max;
   
   return 0;
}
I have been working on this problem for a while and I am currently stuck why there isn't any output. I feel like I didn't write the while loop correctly but can't seem to figure out how to fix it. Any help is appreciated.
 
     
    