Code:
#include <iostream>
using namespace std;
void initialize(double [], int);
void process (double [], int);
void format (void);
void display (double [], int);
int main()
{
double array[5];
cout << "Enter five numbers\n" << endl;
initialize(array, 5);
process(array, 5);
format();
display(array, 5);
return 0;
}
void initialize(double array[], int size)
{
for (register int i = 0; i < size; i++)
cin >> array[i];
}
void process (double array[], int size)
{
for (register int i = 0; i < size; i++)
array[i] = array[i] * 2;
}
void format (void)
{
cout.precision(2);
cout.width(10);
cout.setf(ios::fixed | ios:: showpoint);
}
void display (double array[], int size)
{
cout << "\nThe numbers doubled are..." << endl;
for (register int i = 0; i < size; i++)
cout << array[i] << endl;
}
Why doesn't cout.width(10) work?
The only way I can get it to work is to change the cout statement in the display function's definition to cout << setw(10) << array[i] << endl;
I don't want to use that way since it defeats the purpose of having a formatting function, and the setw method requires that I add #include <iomanip>