Hello to all the handsome people who want to save me from my pain,
I am new to c++, and after having done the usual intro stuff like strings, loops, arrays, pointers that w3schools tells you, I decided to write some code. I decided to start with a simple challenge that asks you to write some loops that will sort a few ints from highest to lowest or the other way around, without using the sort function(I was told there was something like this).
And the code is still not working. But this is normal for me as long I can understand why is it not working. (Pls don't answer why it doesn't work, just continue reading)
#include <iostream>
using namespace std;
int age[4] = { 26, 14, 6, 43};
int num = 4;
int a = 0;
double previous = 0;
int chosen = age[a];
void first() {
while (result[0] || result[num] == 0){
for (int i = 0; a != num; i++) {
chosen = age[a];
previous = age[i];
if (chosen < (previous + 0.01) ) {
chosen = result[a];
a++;
previous = age[0];
i = 0;
}
}
}
}
void last()
{
for (int i = 0; i < num; i++) {
cout << result[i] << "\n";
}
}
int main() {
first();
last();
}
So I tried to see if my main "if statement" was properly working and I added an already assigned value of result[0] where the variables were introduced.
int a = 0;
double previous = 0;
result[0] = 20;
int chosen = age[a];
And then when I ran the program this errors occurred:
error C2466: cannot allocate an array of constant size 0
(18,14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
(18,16): error C2440: 'initializing': cannot convert from 'int' to 'int [0]'
(18,12): message : There are no conversions to array types, although there are conversions to references or pointers to arrays
(line 18 is where I assigned result[0])
When I saw this I was like "I guess I am stupid enough and I don't know how to assign arrays", but then I checked if this was the case and I think this is not the case.
And then I understood the first error because I tried changing result[0] to result[4] and it disappeared, but I had no idea what the second error was saying.
So, as one wise man probably said, "If you have coding problems that google cannot answer, go to stack overflow".
And so I did. But the article I found was with code that was equal to my knowledge of Chinese. And if you are still wondering, I do not know a single Chinese word. And I didn't find a better article that could explain how to fix the problem in pure coding for beginners. I just started coding c++ in the pandemic and I don't understand anything other than English yet.
And I would really appreciate if someone could tell me what does this error mean and how is it possible to disappear with his other error friends waiting below him.