Hi, I'm new to this forum!I recently wrote a program in C++ , but I get 19 errors!! I would really apreciate it if someone helped me find the errors of my program.
Here is the code :
#include <iostream>
using std::cout;
using std::endl;
using std::fixed;
using std::showpoint;
#include <iomanip>
using std::setw;
using std::setprecision;
void mean( const int [], int );
void median( int[], int );
void mode( int[], int[], int );
void PrintArray( const int [], int );
void BubbleSort ( int[], int );
void mean( const int answer[], int arraySize )
{
int total = 0;
cout << "*****\nMean\n*****\n";
for ( int i = 0; i < arraySize; i++ )
total += answer[ i ];
cout << fixed << setprecision( 4 );
cout << "The mean is the average value of the data\n"
<< "items.The mean is equal to the total of all\n"
<< "the data items ( " << arraySize " ). The mean value\n"
<< "for this run is : " << total << "/ " << arraySize << "="
<< static_cast< double >( total ) / arraySize << "\n\n";
void PrintArray( const int a[], int size )
{
for ( int i = 0; i < size; i++ ){
if ( i % 20 == 0 )
cout << endl;
cout << setw( 3 ) << a[ i ];
}
}
void median( int answer[], int size )
{
cout << "*****\nMedian\n*****\n";
cout << "The unsorted array of responses is :\n";
PrintArray( answer, size );
BubbleSort( answer, size );
cout << "The sorted array is :\n";
PrintArray( answer, size );
cout << "The median is element " << size / 2
<< "\nof the sorted" << size << "element array."
<< "\nFor this run , the median is " << answer[ size / 2 ] <<"\n\n";
}
void mode( int freq[], int answer[], int size )
{
int largest = 0;
int modeSize = 0;
cout << "*****\nMode\n*****\n";
for ( int i = 1; i <= 9; i++ )
freq[ i ] = 0;
for ( int j = 0; j < size; j++ )
++freq[ answer[ j ] ];
for ( int k = 0; k < freq[ rating ]; k++ )
cout << "*";
}
cout << "\nThe mode is the most frequent value."
<< "\nFor this run , the mode is " << modeSize
<< "\nwhich occured " << largest << " times. " << endl;
Do not fear. Most of the time later errors stems from first (because compiler already understood your code wrong). In your case there are only 2 actual errors, (well, first one has 8 instances).
Take a look on accentuated parts. Remember that whitespace characters (including newline) are optional in most cases in C++. So that part looks like: /*...*/,8,9 6,2,/*...*/. See the problem?
Same thing in each line of your array declaration.
Second error is here: << "the data items ( " << arraySize " ). The mean value\n". You forgot something.
Oh alright! Found the first one , thanks! The other one though ( << "the data items ( " << arraySize " ). The mean value\n" ) is a little tricky.... It sais I missed ';' before 'string'.....