Finding the Largest and Smallest Integers In A Set- Basic
Posted
by
Ka112324
on Stack Overflow
See other posts from Stack Overflow
or by Ka112324
Published on 2012-10-22T20:37:19Z
Indexed on
2012/10/23
17:01 UTC
Read the original article
Hit count: 154
I'm kind of on the right track, however my output is not quite right. The program asks for the number of integers you have and then it asks for those numbers. For an example is says please enter the number of integers, you can put 3. And then you enter 3 numbers. I can't use arrays because I am a beginner student and we have not learned those yet. Using count is the only way that allows me to input integers. What do I need to add to my program? Again I am a general computer science student so I can't use anything advanced. I used include iostream, namespace int main and all that you just cant see it
int data;
int num;
int count=0;
int max=0;
do
{
cout<<"Enter the number of intergers"<<endl;
cin>>num;
while (count<num)
{
cout<<"Please enter a number"<<endl;
cin>>data;
count++;
if (data<min)
{
min=data;
}
if (data>max)
{
max=data;
}
}
cout<<"Smallest integer:"<<min<<endl;
cout<<"Largest integer:"<<max<<endl;
cout<<"Would you like to continue?"<<endl;
cin>>ans;
} while ((ans=='y')||(ans=='Y'));
return 0; }
© Stack Overflow or respective owner