Help please, I can't understand where is mistake, after compilation, program has nothing to show. Need to create 2 stacks, one of them will contain random numbers, the other will contain only those numbers from first stack, which greater than average of all numbers in first stack
#include "stdafx.h"
#include <iostream>
#include <ctime>
using namespace std;
struct stack //our stack
{
int num;
stack* ptr = NULL;
};
void addtostack(int &n, stack* p) //add element to stack
{
stack* newstack = new stack;
newstack->num = n;
newstack->ptr = p;
p = newstack;
}
void showstack(stack* p) //show stack
{
stack* current = p;
while (current->ptr)
{
cout << current->num << endl;
current = current->ptr;
}
}
int main()
{
srand(time(NULL));
const int SIZE = 5;
stack* first = new stack;
int rnd;
double average = 0;
for (int i = 0; i < SIZE; i++)
{
rnd = -50 + rand() % 101;
addtostack(rnd, first);
average += rnd;
}
average /= SIZE;
showstack(first);
system("pause > nul");
}