Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<pre>#include <iostream>

using namespace std;

int main()

    int main() {
    int size;
    while (true) {
        cin >> size;
        if (size >=5 && size <=50) {
            break;
        }
    }

    int a[size];

    for (int i = 0; i < size; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < size; i++) {
        cout << a[i] << ", ";
    }
    cout << endl;

    for (int i = size -1; i > 0; i--) {
        cout << a[i] << ", ";
    }
    cout << endl;

    int b[size];
    for (int i = size -1; i > 0; i--) {
        if (i%2==0) {
            b[i] = a[i] * 2;
        } else {
            b[i] = a[i] * 3;
        }
    }
    for (int i = size -1; i > 0; i--) {
        cout << a[i] << ", ";
    }
    cout << endl;

    int c[size * 2];

    for (int i = 0; i < size; i++) {
        c[i] = a[i] * 2;
    }
    for (int i = 0; i < size; i++) {
        c[i+size] = b[i] * 3;
    }
    for (int i = (size*2) - 1; i > 0; i--) {
        cout << a[i] << ", ";
    }
    cout << endl;

    return 0;
}
}


What I have tried:

The error is expected initializer before 'int'. So I programmed many programs like this and it's the first time I'm getting this error. I don't understand why. Can someone please help me?
Posted
Updated 27-Nov-21 18:02pm
v2
Comments
Joe Woodbury 31-Aug-21 4:41am    
As a side note: int a[size]; is a non-standard GCC extension.

Using std::vector would also allow other advantages.

You have two, nested, main function definitions.
Remove, for instance, the outer one and try again.
 
Share this answer
 
Comments
Patrice T 30-Aug-21 7:58am    
+5
Try:
C++
#include <iostream>

using namespace std;

int main()

    int main() {

First rule of C : Exactly 1 main() per program.
 
Share this answer
 
v2
Comments
CPallini 30-Aug-21 7:49am    
You forgot to delete the extra closing brace. :-D
My 5.
Patrice T 30-Aug-21 7:58am    
Left to OP since there is no opening '{'
thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900