In: Computer Science
Develop a C++ program that determines the largest and second largest positive values in a collection of data
Prompt the user to enter integer values until they enter any negative value to quit
Create a loop structure of some sort to execute this input cycle
Maintain the largest and second largest integer as the user inputs data
Display the largest and second largest values entered by the user
#include <iostream>
using namespace std;
int main()
{
int first_largest=0,second_largest=0;
int n;
while(true)
{
cout<<"Enter the number:";
cin>>n;
if(n<0)
break;
if(first_largest<n)
{
second_largest=first_largest;
first_largest=n;
}
else if(second_largest<n)
{second_largest=n;}
}
cout<<"Largest:"<<first_largest<<endl;
cout<<"Second
Largest:"<<second_largest<<endl;
return 0;
}
