When the PrintData function prints out the Average from the average function the number is printed out with a lower case L next to the average number. For example: l9.9 instead of 9.9.
I have added a second PirntData function to see the ten random numbers before they are averaged out.
Here is my new code:
Code:
#include <iostream>
#include <string>
#include <ctime>
//prototype functions
void PrintData(char sLabel[], double dAnswer);
void PrintData(long sLabel[], double size);
void FillArray(long array[], long size);
double Average1(long array[], long size);
using namespace std;
int main()
{
//variables used
const short shMAX = 10;
short shCnt;
long lArr[10];
double dAnswer;
string sName = "bob";
double d2Arr[2][3];
srand((unsigned)time(NULL));
//FillArray called
FillArray(lArr, 10);
dAnswer = Average1(lArr, 10);
PrintData(lArr, 10);
PrintData("lArr", dAnswer);
system("pause");
return 0;
}
void PrintData(char sLabel[], double dAnswer)
{
cout << *sLabel << dAnswer << endl;
}
void PrintData(long sLabel[], double size)
{
for(int cnt = 0; cnt < size; cnt ++)
{
cout << sLabel[cnt] << " ";
}
cout << endl;
}
//#1. FillArray - It will receive the lArr array, an array of long integers,
//from main and a count of the number of elements in the array.
//A random number will be assigned to each element of the array in a loop.
//Use rand(). This function has no return value, a void function.
void FillArray(long array[], long size)
{
for(int count = 0; count < size; count++)
{
array[count] = rand()%20 +1;
}
}
//#2a Average1 - It will receive the array lArr and a count of the items.
//It will add up the total and then return the average as a double.
//Use subscript notation throughout. In main call the function PrintData
//to print the average returned. This function receives 2 arguments and returns a double.
double Average1(long array[], long size)
{
double total = 0.0;
double average;
for(int count = 0; count < size; count++)
{
total += array[count];
}
average = (double)total / size;
return average;
}
Can someone explain why I get a lower case L with the output.
Thanks,
R.