Question

Write a program that accepts an indefinite set of numbers until the user enters “-1”. In...

Write a program that accepts an indefinite set of numbers until the user enters “-1”. In other words, the program keeps accepting new values until the user provides a “-1” (your program accepts all values, and discards the “-1”). When done, the program prints back to the user: (i) the sum of all numbers entered (except -1), (ii) the minimum value seen across all numbers (except -1), and (iii) the maximum value across all numbers (except -1). The language is C++

0 0
Add a comment Improve this question Transcribed image text
Answer #1


#include <iostream>

using namespace std;

int main()
{
  
int min,max,sum=0,num,flag=1;
cout<<"Enter numbers (-1 to quit): ";
while(true){
cin>>num;
//break if user gives -1
if(num==-1)
break;
// for the first time
// assuming first num as min and max
if(flag){
flag=0;
min=num;
max=num;
}
else{
if(num<min)
min=num;
if(num>max)
max=num;
}
sum+=num;
}
cout<<"Sum : "<<sum<<endl;
cout<<"Min : "<<min<<endl;
cout<<"Max : "<<max<<endl;
return 0;
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
Write a program that accepts an indefinite set of numbers until the user enters “-1”. In...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT