C++ Mode calculator problem (noob having problems)

  • Context: Comp Sci 
  • Thread starter Thread starter USN2ENG
  • Start date Start date
  • Tags Tags
    C++ Calculator Mode
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 2K views
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.