Comp Sci C++ Mode calculator problem (noob having problems)

AI Thread Summary
The user is learning C++ in an engineering class and is attempting to write a program to calculate the mean, median, and mode of ten random numbers. They successfully implemented the mean and median but are struggling with counting occurrences for the mode, encountering several compilation errors in their code. The errors stemmed from mistakenly declaring the `fakearray` variable twice and incorrect syntax for incrementing its values. After realizing the mistake, the user expressed gratitude for any assistance and noted they would improve code readability in future posts. The discussion highlights common beginner challenges in programming with C++.
USN2ENG
Messages
107
Reaction score
0

Homework Statement


Just as a background this is my first time ever learning to program. I am in an engineering C++ class. I had to write a program that took in ten random numbers and then found the mean median and mode. I got the first two and was able to figure out how to sort correctly. But now I am trying to set up a second array to count the number occurrences of the first array and I am getting a couple errors. I googled the errors but I am still not sure what it exactly means.


The Attempt at a Solution


My code snippet (if you need more, just let me know, I just didnt want to fill the whole page up):

int fakearray[10]={1,1,1,1,1,1,1,1,1,1};
int temp = 0;

for(int y=0; y < 10; y++)
{
temp=Bubble[y];
for(int x=0; x<10;x++){
if(Bubble[x]==temp){
int fakearray[y]= fakearray[y]++; //This is where all the errors are pointing
}
}
}

The errors I am getting:
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
error C2440: 'initializing' : cannot convert from 'int' to 'int []'
There are no conversions to array types, although there are conversions to references or pointers to arrays

Thanks to anyone that can help point me to the right path!
 
Physics news on Phys.org
Haha, nevermind, I just realized I had int fakearray twice...well thanks if you looked!
 
Put your programs in [noparse]
Code:
[/noparse] tags to make them more readable.
 
Thanks! Will do next time, didn't know that was an option.
 

Similar threads

Replies
2
Views
2K
Replies
4
Views
1K
Replies
5
Views
3K
Replies
5
Views
2K
Replies
3
Views
1K
Replies
7
Views
3K
Replies
23
Views
8K
Back
Top