Help with setting the maximum and minimum numbers in a series
Dec 6, 2013 at 7:40pm UTC
Okay, so, I need to write a program that not only calculates the minimum and maximum, but also calculates the average and the difference between the largest and the smallest.
Here's the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#include <iostream.h>
#include <conio.h>
#inlcude <math.h>
#include <windows.h>
using namespace std;
int main()
{
int n;
long num1, num2, num3, num4, num5, num6, num7, num8, num9, average, difference, min, max;
do
{
cout << "Enter a maximum of 9 integers (enter 0 to quit at any point):" << endl;
min = 0;
max = 0;
if (cin == 0)
{break ;}
for (n = 0; n <= 9;)
cin >> num1;
n = n++;
cin >> num2;
n = n++;
cin >> num3;
n = n++;
cin >> num4;
n = n++;
cin >> num5;
n = n++;
cin >> num6;
n = n++;
cin >> num7;
n = n++;
cin >> num8;
n = n++;
cin >> num9;
n = n++;
break ;
} while (1);
average = (num1 + num2 + num3 + num4 + num5 + num6 + num7 + num8 + num9) / n;
while (cin != 0)
{
if (std::cin >= max)
{ max = cin; }
else if (std::cin =< min)
{ min = cin; }
}
difference = max - min;
cout << "Alright let's hope this works." << endl;
cout << "Numer of integers entered: " << n << endl;
cout << "Average of the integers entered: " << average << endl;
cout << "Largest integer: " << max << endl;
cout << "Smallest number: " << min << endl;
cout << "And the range of the integers: " << difference << endl;
Sleep(2000);
cout << "Did it work?" << endl;
Sleep(1000);
cout << "If not I will punch something" ;
Sleep(1000);
cout << "Oh well, see ya!" ;
Sleep(2000);
return 0;
}
I know the problem is the "sdt::cin" but I don't know what else to do, any help please?
Dec 9, 2013 at 7:24am UTC
take the "std::" out
Topic archived. No new replies allowed.