Hey, I'm pretty new to programming and I'm writing a program for my class. I can't figure out why my <iomanip> isn't working.. I'll post a copy of the code (I'm aware it's bugged, as it's not returning the proper values, but the format of the output is the issue). I'm sure I called everything I need to but it reads 'fixed' as an undefined value, which leads me to believe I might not have the proper library on my computer. If this is the case, how can I get it?? Thanks.
//**********************************************
//**********************************************
// N/A Prof: N/A
// Assignment # 6 Question # 2
// Program: Arrays and Functions
// Purpose: Calculate and display the largest
// element, mean, standard deviation,
// and median of a user-defined set
// of integers.
// Author: Cold_Demon388
// Date: 16 November 2009
//**********************************************
//**********************************************
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int indexMax(const int x[], int length);
void remove(int x[], int &length, int index);
int readSeq(int x[]);
void writeArray(int x[], int length);
double mean(const int x[], int length);
double stdDeviation(const int x[], int length, double mean);
double median(int x[], int length);
int main()
{
// Variable Declarations
const int MAX_SIZE = 512;
int x[MAX_SIZE];
// Get User Input
int length = readSeq(x);
// Calcualtions and Output
cout << "Largest: " << x[indexMax(x, length)] << endl;
cout << fixed << setprecision(1) << "Mean: " << mean(x, length) << endl;
cout << setprecision(3) << "Std Deviation: " << stdDeviation(x, length, mean(x, length)) << endl;
cout << setprecision(1) << "Median: " << median(x, length) << endl;
return 0;
}
int indexMax(const int x[], int length)
{
int i = 0;
int max = x[0];
int index = 0;
//finds max value in array and returns the index to that val
while (i < length - 1)
{
if (max < x[i+1])
{
max = x[i+1];
index++;
}
i++;
}
return index;
}
void remove(int x[], int &length, int index)
{
//shifts value at x[index+1] to x[index] and decrements length by 1
while (index <= length - 1)
{
x[index] = x[index+1];
index++;
}
length--;
}
int readSeq(int x[])
{
int input;
int length = 0;
cin >> input;
while(input != 0 && length <= 512)
{
x[length] = input;
length++;
cin >> input;
}
return length;
}
void writeArray(int x[], int length)
{
int i = 0;
while (i < length)
{
cout << x[i] << " ";
i++;
}
}
double mean(const int x[], int length)
{
int i = 0;
int sum;
while (i < length)
{
sum += x[i];
i++;
}
return sum / i;
}
double stdDeviation(const int x[], int length, double mean)
{
int i = 0;
double sum;
while (i < length)
{
sum += (x[i] - mean) / length;
i++;
}
return sqrt(sum);
}
double median(int x[], int length)
{
int i = static_cast <int> (length / 2);
int originalLength = length;
int largerNum;
if (originalLength % 2 == 1)
{
while (originalLength - i < length)
remove(x, length, indexMax(x, length));
return x[indexMax(x, length)];
}
else
{
while (originalLength - i + 1 < length)
remove(x, length, indexMax(x, length));
largerNum = indexMax(x, length);
remove(x, length, largerNum);
return (x[largerNum] + x[indexMax(x, length)]) / 2;
}
}
Thanks again everyone. Take care.