1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
/**
* This program uses if statments to sort 3 integers entered in by a user in
* numerical order from lowest to highest. Then it will find the sum of all
* the integers entered and the average. It will loop 9 times
*
* @creator
*/
int main(int, char**) {
float sum=0;
float average=0;
for(int i= 0; i<9; ++i) {
int x,y,z;
int order;
cout<<"Enter 3 integers: ";
cin>>x>>y>>z;
if ((x>y && y>z))
order = x,y,z;
if ((x>z) && (z>y))
order = x,z,y;
if ((y>x) && (x>z))
order = y,x,z;
if ((y>z) && (z>x))
order = y,z,x;
if ((z>x) && (x>y))
order = z,x,y;
if ((z>y) && (y>x))
order = z,y,x;
cout<<x<<" "<<y<<" "<<z<<" sorted is "<<order<<endl;
cout<<endl;
sum+= x+y+z;
}
average = sum/27;
cout <<"The sum of all the integers is: " <<sum<<endl;
cout <<"The average of all the integers is: " <<average<<endl;
cout<<endl;
(void) system("pause");
return EXIT_SUCCESS;
}
|