got some homework to produce a program that loads and displays double-precision random numbers with an array size of 20. i know its messy but not to good at this
#include <iostream> //required for cin, cout, endl
#include <cstdlib> //rewuired for setw(), setfill()
#include <iomanip>
using namespace std;
void printArray(int arr[]);
void fillRandArray(int arr[]);
void fillDecimalArray(double dArr[]);
void printDecimalArray (double dArr[]);
int main()
{
int random[21];
double decimal[21];
rand();
fillRandArray(random);
fillDecimalArray(decimal);
printArray(random);
printDecimalArray(decimal);
cin.get();
cin.get();
return 0;
}
void fillRandArray(int arr[])
{
for (int i = 1; i < 21; i++)
{
arr[i] = rand() % 100 + 1;
}
}//end load of rand array
void fillDecimalArray(double dArr[ ])
{
for (double i = 1; i <21; i++)
{
dArr[i] = static_cast<double>(rand()%100)/10;
}
}
void printArray(int arr[])
{
cout << " 5x4 Array" <<endl;
cout <<endl;
int cols = 5;
for(int i = 1; i < 21; i++)
{
cout << setw(5) << setfill(' ');
cout << arr[i];
if(i%cols == 0)
cout << endl;
}//end print array
}//end of printArray()
void printDecimalArray (double dArr[])
{
int cols = 4;
for (double i = 1; i <21; i++)
{
cout << setw(5) << setfill(' ');
int precision = 2;
cout << dArr[i];
cout << endl;
}
}
needs to be displayed in 4x5 table errors are ' invalid types 'double*[double]' for array subscript '
Aucun commentaire:
Enregistrer un commentaire