#include <iostream>
#include <stdio.h>
usingnamespace std;
int main ()
{
int a,b,c,d,e,f,g,h;
int largest, smallest;
cout<<"Enter a 1st number ";
cin>>a;
cout<<"Enter a 2nd number ";
cin>>b;
cout<<"Enter a 3rd number ";
cin>>c;
cout<<"Enter a 4th number ";
cin>>d;
cout<<"Enter a 5th number ";
cin>>e;
cout<<"Enter a 6th number ";
cin>>f;
cout<<"Enter a 7th number ";
cin>>g;
cout<<"Enter a 8th number ";
cin>>h;
if (a>b)
{
largest = a;
smallest = b;
}
else
{
largest = b;
smallest = a;
}
if (largest < c)
{
largest = c;
}
if (largest < d)
{
largest = d;
}
if (largest < e)
{
largest = e;
}
if (largest < f)
{
largest = f;
}
if (largest < g)
{
largest = g;
}
if (largest < h)
{
largest = h;
}
if (smallest > c)
{
smallest = c;
}
if (smallest > d)
{
smallest = d;
}
if (smallest > e)
{
smallest = e;
}
if (smallest > f)
{
smallest = f;
}
if (smallest > g)
{
smallest = g;
}
if (smallest > h)
{
smallest = h;
}
cout<<"The largest is "<<largest;
cout<<"\n";
cout<<"The smallest is "<<smallest;
return 0;
}
int a; // current number
int largest;
int smallest;
And instead of lots of similar-looking cin and cout statements, use a loop. Have you learned about loops yet? (You will need another variable to control the counting of the loop).
See tutorial: http://www.cplusplus.com/doc/tutorial/control/