A program that inputs three integers from the keyboard and prints the sum, average, product, smallest and largest of these numbers.

93 Views
``````/******************************************************

** Name:

** Filename: numbers1.cpp

** Project #: Deitel & Deitel 1.26

** Project Description: Write a program that inputs three integers
from the keyboard and prints the sum, average, product, smallest
and largest of these numbers.

** Output:
Sum of three integers
Average of three intergers
Product of three integers
Smallest of three integers
Largest of three integers

** Input:
Three integers from the keyboard

** Algorithm:
Explain function to be performed
Direct user to input three integers
Take the three integers that are input and calculate
Sum
Average
Product
Smallest integer
Largest integer
Print sum
Print average
Print product
Print smallest integer
Print largest integer

******************************************************/

// Include files
#include <iostream>  // used for cin, cout
#include <conio.h>
using namespace std;

// Global Type Declarations

// Function Prototypes
void instruct (void);
void pause ();

//Global Variables - should not be used without good reason.

int main ()
{
// Declaration section
double integer1, integer2, integer3, sum, average, product;

// Executable section
instruct ();
cout << "Input three different integers: ";
cin >> integer1 >> integer2 >> integer3;
sum = integer1 + integer2 + integer3;
average = (integer1 + integer2 + integer3) / 3;
product = integer1 * integer2 * integer3;
cout << "Sum is " << sum
<< "\nAverage is " << average
<< "\nProduct is " << product << endl;
if ( integer1 < integer2 )
if ( integer1 < integer3 )
cout << "Smallest is " << integer1 << endl;
if ( integer1 == integer2 )
if ( integer1 < integer3 )
cout << "Smallest is " << integer1 << endl;
if ( integer2 < integer1 )
if ( integer2 < integer3 )
cout << "Smallest is " << integer2 << endl;
if ( integer2 == integer3 )
if ( integer2 < integer1 )
cout << "Smallest is " << integer2 << endl;
if ( integer3 < integer1 )
if ( integer3 < integer2 )
cout << "Smallest is " << integer3 << endl;
if ( integer3 == integer1 )
if ( integer3 < integer2 )
cout << "Smallest is " << integer3 << endl;
if ( integer1 > integer2 )
if ( integer1 > integer3 )
cout << "Largest is " << integer1 << endl;
if ( integer1 == integer2 )
if ( integer1 > integer3 )
cout << "Largest is " << integer1 << endl;
if ( integer2 > integer1 )
if ( integer2 > integer3 )
cout << "Largest is " << integer2 << endl;
if ( integer2 == integer3 )
if ( integer2 > integer1 )
cout << "Largest is " << integer2 << endl;
if ( integer3 > integer1 )
if ( integer3 > integer2 )
cout << "Largest is " << integer3 << endl;
if ( integer3 == integer1 )
if ( integer3 > integer2 )
cout << "Largest is " << integer3 << endl;
if ( integer1 == integer2 )
if ( integer1 == integer3 )
cout << "All integers are equal\n";

pause ();
return 0;

}

void instruct (void)
{
// Declaration section

// Executable section
cout << "Choose three integers to input below. The program will\n"
<< "then print the sum, the average, the smallest, and the\n"
<< "largest of the three integers that have been input.\n "<< endl;
}

void pause ()
{
// Declaration section

// Executable section
cout << "\nPress any key to continue...";
getch();
cout << "\r";
cout << "                            ";
cout << "\r";
}

/*
Program Output

Choose three integers to input below. The program will
then print the sum, the average, the smallest, and the
largest of the three integers that have been input.

Input three different integers: 12 19 25
Sum is 56
Average is 18.6667
Product is 5700
Smallest is 12
Largest is 25

Press any key to continue...

*/``````