Write a C++ program that requests five integer values from the user. It then pri
ID: 663767 • Letter: W
Question
Write a C++ program that requests five integer values from the user. It then prints the maximum and
minimum values entered. If the user enters the values 3, 2, 5, 0, and 1, the program would indicate
that 5 is the maximum and 0 is the minimum. Your program should handle ties properly; for example,
if the user enters 2, 4 2, 3 and 3, the program should report 2 as the minimum and 4 as maximum.
Write a C++ program that allows the user to enter any number of non-negative double-precision
floating-point values. The user terminates the input list with any negative value. The program then
prints the sum, average (arithmetic mean), maximum, and minimum of the values entered. The
terminating negative value is not used in the computations.
Explanation / Answer
1)
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e;
clrscr();
cout<<" Please enter the value of A: ";
cin>>"%d",&a;
cout<<" Please enter the value of B: ";
cin>>"%d",&b;
cout<<" Please enter the value of C: ";
cin>>"%d",&c;
cout<<" Please enter the value of D: ";
cin>>"%d",&d);
cout<<" Please enter the value of E: ";
cin>>"%d",&e;
if (a < b && a < c && a < d && a < e)
cout<<(" %d is Minimum which is value of A",a);
else if(b < a && b < c && b < d && a < e)
cout<<(" %d is Minimum which is value of B",b);
else if(c < a && c < b && c < d && c < e)
cout<<(" %d is Minimum which is value of C",c);
else if(d < a && d < b && d < c && d < e)
cout<<(" %d is Minimum which is value of D",d);
else if (e < a && e < b && e < c && e < d);
cout<<(" %d is Minimum which is value of E",e);
if (a > b && a > c && a > d && a > e)
cout<<" %d is Maximum which is value of A"<<a;
else if(b > a && b > c && b > d && a > e)
cout<<(" %d is Maximum which is value of B",b);
else if (c > a && c > b && c > d && c > e)
cout<<(" %d is Minimum which is value of C",c);
else if(d > a && d > b && d > c && d > e)
cout<<(" %d is Minimum which is value of D",d);
else if(e > a && e > b && e > c && e > d)
cout<<(" %d is Minimum which is value of E",e);
getch();
}
2)
#include <iostream.h>
void main()
{
float value, sum;
float average, minimum, maximum;
int count;
sum = 0.0;
count = 0;
cout << "Enter a value: ";
cin >> value;
minimum = value;
maximum = value;
while (value >= 0.0)
{
// process value
sum += value;
count++;
if (value > maximum)
maximum = value;
else if (value < minimum)
minimum = value;
// get next value
cout << "Enter a value: ";
cin >> value;
}
if (count == 0)
cout << "No data entry" << endl;
else
{
average = sum / count;
cout << "There were " << count << " numbers" << endl;
cout << "Average was " << average << endl;
cout << "Minimum was " << minimum << endl;
cout << "Maximum was " << maximum << endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.