Hello, everyone my brother was given an assignment to do in C, I know C++ and C# so I write it out in C++ to get a better understanding of what the brief wants us to do.
I have the program working, but with modifications to the brief.
Brief
Write a program that calculates the Root-Mean-Square (RMS) of a
sequence of numbers whose length and content are determined by the
user. The RMS calculation should be done in a function of prototype
double RMS(double *x, int N), where N is the number of elements
in the array x. Demonstrate its use in a main function which prompts
the user for the length of the sequence, and then the values of this
sequence (e.g. if the user gives 3 as a sequence length, he/she should
thereafter be asked for 3 values).
This is what I wrote
What Im not sure of is the prototype in the brief.Code:#include <iostream> #include <math.h> double RMS(double x, int N); using namespace std; int main() { int arraysize(0); double total(0); double content(0); cout << "How many number's should there be." << endl; cin >> arraysize; double array[arraysize]; for(int i = 0; i < arraysize; ++i) { cout << "Enter number " << i << endl; cin >> content; array[i] += content; total += content; } cout << RMS(total, arraysize); return 0; } double RMS(double x, int N) { double result(0); result = x * x / N; sqrt(result); return result; }
double RMS(double *x, int N)
Is double *x a pointer or does he just mean array because they are similar but not the same.
I did it all from memory so go easy on me if there is some noobish mistakes the last time I used C++ was a long time ago.



2Likes
LinkBack URL
About LinkBacks




