C++ Mode calculator problem (noob having problems)

  • Context: Comp Sci 
  • Thread starter Thread starter USN2ENG
  • Start date Start date
  • Tags Tags
    C++ Calculator Mode
Click For Summary

Discussion Overview

The discussion revolves around a programming problem encountered by a beginner in a C++ engineering class. The participant is trying to implement a mode calculation in their program, which involves counting occurrences of numbers in an array. The focus is on debugging code and understanding error messages related to array manipulation.

Discussion Character

  • Homework-related
  • Technical explanation
  • Exploratory

Main Points Raised

  • The participant describes their attempt to create a second array to count occurrences of numbers from a first array, but encounters several errors in their code.
  • The participant shares a code snippet and specifies the line where they are facing issues, seeking help to understand the errors.
  • One error mentioned relates to the declaration of the array, indicating a potential misunderstanding of variable scope or initialization.
  • A later post indicates that the participant resolved their issue by realizing they had mistakenly declared the same variable twice.
  • Another participant suggests using code tags for better readability of the program code in future posts.

Areas of Agreement / Disagreement

The discussion appears to be resolved for the original poster, as they identified and corrected their mistake. However, there is no broader consensus or ongoing debate regarding the programming concepts discussed.

Contextual Notes

The original post indicates a lack of understanding of the error messages and array handling in C++, which may suggest limitations in the participant's foundational knowledge of programming concepts.

Who May Find This Useful

Beginner programmers, particularly those learning C++ and dealing with array manipulation and debugging, may find this discussion relevant.

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 ·
Replies
2
Views
2K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
7
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 23 ·
Replies
23
Views
9K