| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I need some help on this i cant get the min to come up correctly
If any1 could figure out the problem quickly i would really appropriate it. The min doesnt come up correctly it shows a weird looking number.
#include <iostream> #include <cmath> #include <conio.h> using namespace std; int main() { const int TEMPERATURE = 100; float ave = 0.0; float sdev = 0.0; float temp_read; float read[TEMPERATURE]; float max, maxValue; float min, minValue; int i, max_location, min_location; do { cout << "Enter the number of Temperarure readings: "; cin >> temp_read; if ((temp_read < 1) || (temp_read > TEMPERATURE)) cout << "The number of readings is too high!!! \nLimit the number of Temperature readings to 100 \n"; } while ((temp_read< 1) || (temp_read > TEMPERATURE)); for (int i = 0;i < temp_read;i++) { cout << "Enter the temperature reading#" << i+1 << ": "; cin >> read[i]; ave = ave + read[i]; } ave = ave / temp_read; cout << "The temperature average is: " << ave << "\n"; for (int i = 0;i < temp_read;i++) { sdev = sdev + (read[i] - ave)*(read[i] - ave); } sdev = sdev / temp_read; sdev = sqrt(sdev); cout << "The Temperature standard deviation is: " << sdev << "\n"; minValue = read[TEMPERATURE];{ min = read[0]; for (i=0; i<TEMPERATURE; i++) { if (read[i]<min) { min = read[i]; min_location = i+1; } } cout << "The minimun Temperature is: " << min <<" in reading#" << min_location << endl; }; maxValue = read[TEMPERATURE];{ max = read[0]; for (i=0; i<TEMPERATURE; i++) { if (read[i]>max) { max = read[i]; max_location = i+1; } } cout << "The maximun Temperature is: " << max <<" in reading#" << max_location << endl; }; cout << "Press any key to continue"; _getch(); return 0; } |
|
#2
|
|||
|
|||
|
the thing works now XD but the numbering of readings is wrong...
Code:
#include <iostream>
#include <cmath>
#include <conio.h>
using namespace std;
int main()
{
const int TEMPERATURE = 100;
float ave = 0.0;
float sdev = 0.0;
float temp_read;
float read[TEMPERATURE];
float max, maxValue;
float min, minValue;
int i, max_location, min_location;
do
{
cout << "Enter the number of Temperarure readings: ";
cin >> temp_read;
if ((temp_read < 1) || (temp_read > TEMPERATURE))
cout << "The number of readings is too high!!! \nLimit the number of Temperature readings to 100 \n";
} while ((temp_read< 1) || (temp_read > TEMPERATURE));
for (int i = 0;i < temp_read;i++)
{
cout << "Enter the temperature reading#" << i+1 << ": ";
cin >> read[i];
ave = ave + read[i];
}
ave = ave / temp_read;
cout << "The temperature average is: " << ave << "\n";
for (int i = 0;i < temp_read;i++)
{
sdev = sdev + (read[i] - ave)*(read[i] - ave);
}
sdev = sdev / temp_read;
sdev = sqrt(sdev);
cout << "The Temperature standard deviation is: " << sdev << fixed << "\n";
minValue = read[TEMPERATURE];{
min = read[0];
for (i=0; i<temp_read; i++) {
if (read[i]<min) {
min = read[i];
min_location = i+1;
}
}
cout << "The minimun Temperature is: " << min << fixed <<" in reading#" << min_location << endl;
};
maxValue = read[TEMPERATURE];{
max = read[0];
for (i=0; i<temp_read; i++) {
if (read[i]>max) {
max = read[i];
max_location = i+1;
}
}
cout << "The maximun Temperature is: " << max << fixed <<" in reading#" << max_location << endl;
};
cout << "Press any key to continue";
_getch();
return 0;
}
cheers! ![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > I need some help on this i cant get the min to come up correctly |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|