write a program with a loop that lets the user enter a seriesof integers, follow
ID: 3609572 • Letter: W
Question
write a program with a loop that lets the user enter a seriesof integers, followed by a -99 to signal the end of the sereies.After all the numbers have been entered, the program should displaythe largest and numbers entered. i honestly dont know where to start on this one. if it were aconstant number being entered then i could write a series of ifelse statements using relational operators like if x<y display"x, y" but i have no idea how to write it with an underterminedamount of input numbers. anything will help immensely. if you write the majority of thecode it would help me out so much to see the basic idea of how itshould be put together, but i realize writing code takes time.either way, help is really appreciated! write a program with a loop that lets the user enter a seriesof integers, followed by a -99 to signal the end of the sereies.After all the numbers have been entered, the program should displaythe largest and numbers entered. i honestly dont know where to start on this one. if it were aconstant number being entered then i could write a series of ifelse statements using relational operators like if x<y display"x, y" but i have no idea how to write it with an underterminedamount of input numbers. anything will help immensely. if you write the majority of thecode it would help me out so much to see the basic idea of how itshould be put together, but i realize writing code takes time.either way, help is really appreciated!Explanation / Answer
please rate - thanks#include <iostream>
#include <fstream>
using namespace std;
int main(void)
{
int i=0,j,num[50],large;
cout<<"Enter a number(-99 to stop):";
cin>>num[i];
large=num[0];
while(num[i]!=-99)
{if(num[i]>large)
large=num[i];
i++;
cout<<"Enter a number(-99 tostop):";
cin>>num[i];
}
cout<<"The numbers are: ";
for(j=0;j<i;j++)
cout<<num[j]<<" ";
cout<<" The largest number is:"<<large<<endl;
system("pause");
return 0;
}
with smallest number
be sure you see the correction in other post (line of code inred)
#include <iostream>
#include <fstream>
using namespace std;
int main(void)
{
int i=0,j,num[50],large,small;
cout<<"Enter a number(-99 to stop):";
cin>>num[i];
large=num[0];
small=num[0];
while(num[i]!=-99)
{if(num[i]>large)
large=num[i];
if(num[i]<small)
small=num[i];
i++;
cout<<"Enter a number(-99 tostop):";
cin>>num[i];
}
cout<<"The numbers are: ";
for(j=0;j<i;j++)
cout<<num[j]<<" ";
cout<<" The largest number is:"<<large<<endl;
cout<<"The smallest number is:"<<small<<endl;
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.