# Arrays and Math

Page 1 of 1

## 1 Replies - 620 Views - Last Post: 01 August 2014 - 06:27 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=351408&amp;s=b9312d89299c4b1eef7a0265e50619d8&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Gamme40

• D.I.C Head

Reputation: 0
• Posts: 65
• Joined: 16-October 11

# Arrays and Math

Posted 01 August 2014 - 06:22 AM

Good evening gents,

I am a beginner C++ programmer and i'm experiencing some difficulty with a task i have...

This is my code so far. I am working with functions and i can't seem to form the main.cpp file to work in conjunction wth the rms.cpp file. I am receiving the errors that are connected with the MATRIX_ROWS and MATRIX_COLUMNS being out of scope, even though they have been pre-declared in the rms.h file...

Here is what I have so far. The object of this program is that the rootMeanSquare accepts an array of type float, and an int indicating the number of elements in the array. It has to return the square root of the mean of the squares of the elements in this array.

The matrixRMS will accept two arguments, a 2D array of floats and a 1D array of floats... This function writes values to the second parameter (the 1D array)... the value it writes to the array is determined by taking the row of each matrix and using it in conjuction with the RMS of the sum total and storing it there.

This is rms.cpp
```#ifndef RMS_H
#define RMS_H
#include "rms.h"
#include "math.h"
#include <iostream>
#include <string>
#include <stdio.h>
#include <ctype.h>
using namespace std;

float rootMeanSquare(const float array[], int count)
{
float squareRt;
int x;
double sumOfSquare = 0;

for(x = 0; x < sizeof(array); x++)
{
sumOfSquare += pow(array[x], 2);
}

squareRt = sqrt(sumOfSquare/count);

return squareRt;
}

void matrixRMS(const float matrix[][5], float rowRMS[])
{
int row;
int col;
float sumOfRow = 0;

for(row = 0; row < matrix[row][col];row++)
{
for(col = 0; col < matrix[row][col]; col++)
{
sumOfRow += matrix[row][col];
}

rowRMS[row] = sumOfRow;
sumOfRow = 0;
}

rootMeanSquare(rowRMS, col);
}
#endif
```

this is rms.h we are not allowed to modify this at all:
```#ifndef RMS_H
#define RMS_H

float rootMeanSquare(const float array[], int count);

const int MATRIX_ROWS = 3;
const int MATRIX_COLUMNS = 5;

void matrixRMS(const float matrix[][MATRIX_COLUMNS], float rowRMS[]);

#endif

```

Thanks in advance

Is This A Good Question/Topic? 0

## Replies To: Arrays and Math

### #2 Skydiver

• Code herder

Reputation: 6117
• Posts: 21,060
• Joined: 05-May 12

## Re: Arrays and Math

Posted 01 August 2014 - 06:27 AM

It's because you put header guards within your .cpp file. Why do you have lines 1, 2, and 46 in your .cpp file?
Was This Post Helpful? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }