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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
#include <stdio.h>
/******************************************************************************/
/* */
/* main */
/* */
/******************************************************************************/
/* */
/* Input Variables(arrays): */
/* float temp[20] - Temperature for the scientific experiment */
/* float pressure[20] - Pressure for scientific experiment */
/* ch - Used for exiting program */
/* */
/* Output Variables (Calculated): */
/* float temp_max - Final max temperature */
/* float pressure_max - Final max pressure */
/* float temp_min - Final min temperature */
/* float pressure_min - Final min pressure */
/* */
/* Functions Called */
/* float temp_extreme() - Finds temp-max and temp_min */
/* float pressure_extreme() - Finds pressure_max and pressure_min */
/* */
/* Variables local to temp_extreme() and pressure_extreme() */
/* */
/* float temp_max1 - Largest temperature in the temp array */
/* float temp_min1 - Smallest number in the temp array */
/* float pressure_max1 - Largest pressure in the pressure array */
/* float pressure_min1 - Smallest pressure in the pressure array */
/* */
/******************************************************************************/
float temp[20];
float pressure[20];
float temp_extreme(float, float, int);
float pressure_extreme(float, float, int);
int main()
{
float temp_max = 0;
float temp_min = 0;
float pressure_max = 0;
float pressure_min = 0;
int ch;
int count = 0;
printf("Please input the 20 temperature and pressure readings\n");
for(; count < 20; count++)
{
printf("Count = %d \n", count);
printf("Temperature: ");
scanf("%f", &temp[count]);
printf("Pressure: ");
scanf("%f", &pressure[count]);
temp_extreme(temp_max, temp_min, count);
pressure_extreme(pressure_max, pressure_min, count);
}
printf("Lowest Temperature: %f degrees\nHighest Temperature: %f degrees\n Lowest Pressure: %f \n Highest Pressure: %f \n",temp_min, temp_max, pressure_min, pressure_max);
while ((ch = getchar()) != '\n' && ch != EOF);
{
printf ("\n\nPress enter to close the program\n\n");
getchar ();
return 0;
}
return 0;
}
/******************************************************************************/
/* */
/* float temp_extreme(float, float, int) */
/* */
/******************************************************************************/
/* */
/* Variables passed: */
/* temp_max -> temp_max1 */
/* temp_min -> temp_min1 */
/* */
/******************************************************************************/
float temp_extreme(float temp_max1, float temp_min1, int count1)
{
/* If-Else Initializes max1 and min1 to the value of temp[count1] */
/* This enables a comparison for after the initial count from main(), setting */
/* the scene for the else statment, which compares temp_max1 and temp_min1 */
/* to the value of the current array element (based on the count of the for */
/* loop in main() */
printf("%d \n", count1);
if(count1 = 0)
{
temp_max1 = temp[count1];
temp_min1 = temp[count1];
printf("inital max: %f\n min: %f \n", temp_max1, temp_min1);
}
else
{
if(temp_max1 <= temp[count1])
temp_max1 = temp[count1];
if(temp_min1 >= temp[count1])
temp_min1 = temp[count1];
printf("max: %f\n min: %f \n", temp_max1, temp_min1);
return temp_max1, temp_min1;
}
}
/******************************************************************************/
/* */
/* float pressure_extreme(float, float, int) */
/* */
/******************************************************************************/
/* */
/* Variables passed: */
/* pressure_max -> pressure_max1 */
/* pressure_min -> pressure_min1 */
/* */
/******************************************************************************/
float pressure_extreme(float pressure_max1, float pressure_min1, int count1)
{
printf("%d \n", count1);
/* If-Else Initializes max1 and min1 to the value of temp[count1] */
/* This enables a comparison for after the initial count from main(), setting */
/* the scene for the else statment, which compares pressure_max1 and */
/* pressure_min1 to the value of the current array element (based on the */
/* count of the for loop in main() */
if(count1 = 0)
{
pressure_max1 = pressure[count1];
pressure_min1 = pressure[count1];
printf("Initial max: %f\n min: %f \n", pressure_max1, pressure_min1);
}
else
{
if(pressure_max1 <= pressure[count1])
pressure_max1 = pressure[count1];
if(pressure_min1 >= pressure[count1])
pressure_min1 = pressure[count1];
printf("max: %f\n min: %f \n", pressure_max1, pressure_min1);
return pressure_max1, pressure_min1;
}
}
|