Answer to Question #312762 in C++ for Nobody

Question #312762

Write a complete C++ program


a) that will prompt the number of the pancake produce per day, the thickness in mm (millimetres) and the diameter in cm (centimetres) of each pancake,


b) to identify and display minimum and maximum for both dimensions,


c) to calculate and display the average for both the dimensions



1
Expert's answer
2022-03-16T14:48:35-0400
#include <iostream>
using namespace std;


int main() {
    int n;

    cout << "how many pancake were produced? ";
    cin >> n;

    int min_th, max_th, sum_th, thickness;
    int min_d, max_d, sum_d, diameter;

    cout << "Enter thickness (in mm) and diameter (in cm) of the first pancake" << endl;
    cout << "1st pancake: ";
    cin >> thickness >> diameter;

    min_th = max_th = sum_th = thickness;
    min_d = max_d = sum_d = diameter;

    for (int i=1; i<n; i++) {
        cout << i+1 << "th pancake: ";
        cin >> thickness >> diameter;

        if (min_th > thickness) {
            min_th = thickness;
        }
        if (max_th < thickness) {
            max_th = thickness;
        }
        sum_th += thickness;

        if (min_d > diameter) {
            min_d = diameter;
        }
        if (max_d < diameter) {
            max_d = diameter;
        }
        sum_d += diameter;       
    }
    cout << endl;
    cout << "Minimal thickness " << min_th;
    cout << ", maximal thickness " << max_th << endl;
    cout << "Minimal diameter " << min_d;
    cout << ", maximal diameter " << max_d << endl;

    double avg_th = static_cast<double>(sum_th) / n;
    double avg_d = static_cast<double>(sum_d) / n;
    cout << "Average thickness " << avg_th << endl;
    cout << "Average diameter " << avg_d << endl;

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment