Actually I have to write a program that displays average, highest and lowest temperatures which displays something like:
"Enter the number of consecutive days to read their temperature : 5
Enter temperature for day 1: 50
Enter temperature for day 2: 80
Enter temperature for day 3: 30
Enter temperature for day 4: 92
Enter temperature for day 5: 47
The average temperature is 59.80
The highest temperature is 92.00
The lowest temperature is 30.00"
I have wrote something : ) but how I put "Enter days"?? and I have some trouble in end of the code. Please see and help me Please. The code is follows:
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 59 60 61 62 63 64 65 66
|
#include <iostream.h>
#include <stdlib.h>
void highTemp(int[]);
void lowTemp(int []);
void averageTemp(int[]);
using namespace std;
int main(int argc, char *argv[])
{
int n;
cout << "\n\t TEMPERATURE CALCULATION " << endl;
cout << "Enter the number of consecutive days to read their tempetature : ";
int x[n], tmp;
for(int i=0; i < n; i++)
{
for(int j=0; j < n-1; j++)
{
if (x[j] > x[j+1])
{
tmp = x[j];
x[j] = x[j+1];
x[j+1] = tmp;
}
}
}
highTemp(x, n);
lowTemp(x, n);
averageTemp(x, n);
system("pause");
}
void highTemp(int as[], int arraySize)
{
cout << "The highest Temperature is : " << as[arraySize-1] << endl;
}
void lowTemp(int as[])
{
cout << "The lowest temerature is : " << as[] << endl;
}
void averageTemp(int as[], int arraySize)
{
int i; double c = 0;
for(i=0; i < arraySize; i++)
{
c = c+ as[i];
}
c = c/i;
cout << "The average temperature is : " << c << endl;
}
void swap(int *x, int *y)
{
int tmp;
if(*x > *y)
{
tmp = *x;
*x = *y;
*y = tmp;
}
}
|