#include <iostream>
usingnamespace std;
int main()
{
constint SIZE=5;
int numArray[SIZE];
int numbers=0;
int highest;
int lowest;
int count=0;
cout<<"Enter ten numbers and i will tell you the largest and the smallest. "<<endl;
for (count=0; count < SIZE; count++)
{
cout<<"Number "<<count+1<<":";
cin>>numArray[numbers];
highest=numArray[0];
if(numArray[count] > highest)
{
highest = numArray[count];
}
}
cout<<"The highest number is "<<highest<<endl;
system ("pause");
return 0;
}
in the line: cin>>numArray[numbers];
you are setting the index numbers which is 0, and does not change so the only inputted number being stored is the last, thus you see the last number.
#include <iostream>
usingnamespace std;
int main()
{
constint SIZE=10; //should be 10 not 5
int numArray[SIZE];
int highest;
int lowest; //count need not be declared here
cout<<"Enter ten numbers and i will tell you the largest and the smallest. "<<endl;
for (int count=0; count < SIZE; count++) { //gets input
cout<<"Number "<<count+1<<":";
cin>>numArray[count];
}
highest=numArray[0]; //sets highest and lowest
lowest=numArray[0];
for(int count=0; count<SIZE; count++) { //find highest and lowest
if(numArray[count] > highest)
{
highest = numArray[count];
}
if(numArray[count]<lowest) {
lowest=numArray[count];
}
}
cout<<"The highest number is "<<highest<<endl;
cout<<"The lowest number is "<<lowest<<endl;
return(0);
}
#include <iostream>
usingnamespace std;
int main()
{
int lowest,highest,temp;
cout<<"Enter ten numbers and i will tell you the largest and the smallest. "<<endl;
cout<<"Number 1:";
cin>>temp;
highest=temp;
lowest=temp;
for (int count=1; count<10; count++) {
cout<<"Number "<<count+1<<":";
cin>>temp;
if(temp>highest)
{
highest=temp;
}
if(temp<lowest) {
lowest=temp;
}
}
cout<<"The highest number is "<<highest<<endl;
cout<<"The lowest number is "<<lowest<<endl;
return(0);
}
In fact he deal with an input iterator not an array. He would deal with an array if he at first would enter values for the array and only after that start to search the highest and the lowest elements.