1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C++ Mode calculator problem (noob having problems)

  1. Oct 15, 2011 #1
    1. The problem statement, all variables and given/known data
    Just as a background this is my first time ever learning to program. Im 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 im still not sure what it exactly means.


    3. 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!
     
  2. jcsd
  3. Oct 15, 2011 #2
    Haha, nevermind, I just realized I had int fakearray twice....well thanks if you looked!
     
  4. Oct 15, 2011 #3

    Borek

    User Avatar

    Staff: Mentor

    Put your programs in [noparse]
    Code (Text):
     
    [/noparse] tags to make them more readable.
     
  5. Oct 15, 2011 #4
    Thanks! Will do next time, didn't know that was an option.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: C++ Mode calculator problem (noob having problems)
  1. Oscilloscope modes (Replies: 9)

  2. Differential mode gain (Replies: 12)

Loading...