C++
[Program-2] 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).
#include <iostream> using namespace std; int main(){ int sum = 0, min, max, val; cout<<"Enter number: "; cin>>val; min = val; max = val; while(val!=-1){ if(min > val){ min = val; } if(max < val){ max = val; } sum += val; cout<<"Enter number: "; cin>>val; } cout<<"The minimum number was: "<<min<<endl; cout<<"The maximum number was: "<<max<<endl; cout<<"The sum of values entered was: "<<sum<<endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.