Soooo I am having another initializing problem. If I don't initialize "mode" in the function, the program makes me Abort. If I DO initialize it to a number, the result of "mode" comes out to whatever I initialize it to. Such as if I made it mode = 0, then the output shows mode = 0. Or if I made mode = 50, output shows mode = 50. Again, if I don't initialize it, my program does not run properly. Very... annoying. *sigh*
Here is my code:
Any suggestions are very much appreciated.
Here is my code:
// Mode_Function.cpp : Defines the entry point for the console application. // This program belongs to NM. #include "stdafx.h" #include <iostream> using namespace std; // Function prototype. void modeFun (int *, int); const int SIZE = 8; int main() { int modeArr[SIZE]; int *numbers; numbers = modeArr; int c; int mode; cout << "Enter eight integers: "; for (c = 0; c < SIZE; c++) { cin >> modeArr[c]; } // Function Call. modeFun(numbers, SIZE); return 0; } // Function to find the mode of the array. // Function header. void modeFun (int *numbers, int SIZE) { int *array1; array1 = new int[SIZE]; int currvalue = array1[0]; int counter = 1; int p; int mode = 50; int c; for (c = 0; c < SIZE; c++) { array1[c] = 0; } for (c = 0; c < SIZE; c++) { if (p = array1[c]) { array1[c]++; } } for (c = 0; c < SIZE; c++) { if (array1[c] > p) { p = array1[c]; mode = c; } } cout << "The mode is: " << mode << endl; }
Any suggestions are very much appreciated.