Question:
First C++ program. Need help.?
HELP
2010-03-01 00:03:35 UTC
Ok so for our first off im not very good with C, let alone C++. I had a very horrible C teacher so its like trying to cram a lot of things in all at once. Anyways, back to my question. We have to write a program that supposed to be an example of convolution. Thats something i dont fully understand, be were going over it still. Anyhow i was showed how to write a lot of this code but i dont know whats wrong with it. Its only giving me one error on line 18 but im not sure what it is. Please HELP! Heres the code. Forgive me. Again im not good at C++ at all so if this code looks stupid I apologize


#include
using namespace std;

int main()
{
float matrix[4] = {2, 1, 1, 1};
float flip[4];

int i, m;
m = 4;

for(i = 0; i < m; ++i){
flip[i] = matrix[m - 1];


cout << "Flip[i]";

matrix[m] = [m - 1];
}

}
Three answers:
cja
2010-03-01 09:09:33 UTC
As the other responder suggested, the out-of-context [m - 1] is what's causing your compile error. It looks like you're trying to reverse the contents of your array of floats. Not quite convolution, but maybe it's a start for what you're aiming for. See below for some modifications I'd recommend. Notice I changed the name of your array of floats; "matrix" is not a good name for a one-dimensional array.



#include



using namespace std;



const size_t N = 4;



int main(int argc, char *argv[]) {

    float fltArray[N] = {4, 3, 2, 1};

    float flip[N];



    for(size_t i = 0; i < N; ++i) {

        flip[i] = fltArray[N - i - 1];

        cout << "flip[" << i << "] = " << flip[i] << endl;

    }

    return 0;

}



#if 0



Program output:



flip[0] = 1

flip[1] = 2

flip[2] = 3

flip[3] = 4



#endif
あな日田
2010-03-01 00:32:47 UTC
you get the error because of the brackets.

why do you have brackets there??????

the correct version would be :



matrix[m]=m-1;



yet I don't understand what you want.... cuz when you put it like this --- > cout<<"Flip[i]";



you will see Flip[i] on the screen ...4 times...and that's all you get!
?
2016-10-30 14:42:50 UTC
no longer anymore, at one time C++ became into basically an extension of C. considering that then, C has replaced, and so has C++. notwithstanding that being pronounced it quite is not any longer unusual for the comparable application to deliver jointly the two C and C++. the tactic is the comparable, yet there are in basic terms some transformations int he libraries which you opt for the compiler to link to.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...