C++ Do Q7 Use visual studio not Java A mail-order house sells five products whos
ID: 3566204 • Letter: C
Question
C++ Do Q7 Use visual studio not Java A mail-order house sells five products whose retail prices are as follows: nr0dun 1 $2.98; product 2. $4.50; product 3, $9.98; product 4, $4.49 and product 5 $6 87 w an application that reads a series of pairs of numbers as follows: product number quantity sold Your program should use a switch statement to determine the retail price for each product. It should calculate and display the total retail value of all products sold. Use a sentinel-controlled loop to determine when the program should stop looping and display the final results. Find the minimum of a sequence of nonnegative numbers entered by the user, where the user enters a negative number to terminate the input. Find the minimum of a sequence of nonnegative numbers entered by the user. In this time, before reading the numbers, ask the user to enter how many numbers will be input. Find the average of a sequence of nonnegative numbers entered by the user. In this time, before reading the numbers, ask the user to enter how many numbers will be input. Find the maximum, minimum, and average of a sequence of nonnegative numbers entered by the user. In this time, before reading the numbers, ask the user to enter how many numbers will be inputExplanation / Answer
#include <iostream>
using namespace std;
int main(){
float num, min = -1, max = -1, sum = 0;
int numCount, count;
cout << "Enter the total number of numbers to be entered" << endl;
cin >> numCount;
while(numCount--) // will run exactly the entered value times
{
cin >> num; // input number
if(min < 0 || num < min) // first time minimum is set to -1
min = num;
if(max < 0 || num > max) // first time maximum is set to -1
max = num;
sum += num;
}
if(min < 0 ){
// we will reach here only if no numbers are entered or all numbers entered are negative
cout << "No non-negative number entered";
}
else{
cout << "Minimum number is: " << min;
}
if(max < 0){
// we will do nothing because we have already output that all numbers entered were negative.
}
else{
cout << "Maximum number is: " << max;
}
cout << "The average is: " << sum/count; // average = total sum/ total count
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.