This code works properly when user enter max 2 variables... When put more - crash.... please for help :)
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int sum = 0;
int n = 0;
cout << "Enter a number of variables : ";
cin >> n;
int *p = new int[n]; // Allocate n integers
for (int i = 0; i < n; i++)
{
cout << "Enter a number #" << i << ": ";
cin >> p[i];
sum += p[i];
}
cout << "All your numbers: ";
cout << endl;
cout << "The sum is: " << sum << endl;
cout << "Average is: " << (double) sum / n << endl;
for (int i = 0; i < n;)
{
int smallest = p[i];
for (int j = i + 1; j < n; ++j)
{
if (p[j] < p[i])
{
smallest = p[j];
cout << "The smallest number of your enter is: " << p[j];
break;
}
if (p[j] > p[i])
{
cout << "The smallest number of your enter is: " << p[i];
break;
}
}
++i;
}
int smallest = p[0];
for (int i = 1; i < n; i++)
{
if (p[i] < smallest )
smallest = p[i];
}
cout << "The smallest number of your enter is: " << smallest;