I cant figure out why my read in array wont work :/
This is a predetermined lab and so its a bit weirder to work with. Dont i need an int number so that i can read it in from the file thats hardcoded into this lab program?
/*
Problem description:
Write a program to read a huge integer value with 50 digits,
find the digit that appears most frequently in the huge integer, and
print the digit and the number of its occurrences. If two digits appear the
same amount of times in the huge integer, output the larger digit.
*/
#include <iostream>
#include <string>
#include <fstream>
usingnamespace std;
int main( )
{
constint DigitNum = 50; //array capacity
int hugeInt[DigitNum]; //array holding the huge integer
int frequency[10]; // occurrence frequency of each digit 0..9
// i.e. frequency[0] the number of times 0 appears in hugeInt
// i.e. frequency[1] the number of times 1 appears in hugeInt
// ...
// i.e. frequency[9] the number of times 9 appears in hugeInt
char digit; // holding current digit during the reading
int freqIndex; //holding the digit occuring most frequently
//read digits in the huge integer value into the array hugeInt
//read digits in the huge integer value into the array hugeInt
for( int i=0; i<DigitNum; i++ )
{
cin >> hugeInt[i];
}
Thanks, cant say i understand it. so youre basically incrementing the the position INSIDE of the array. But when i compile that it gives me an endless loop problem?
for (int v = 0; v < 10; ++v)
if (frequency[v] > max_count)
{
// do something here
}
}
Unless you're doing something silly to change the value of v within the "Do something here" bit? Assuming you're not, then v will simply increment from 0 to 10, at which point it will fail the condition and the loop will exit.
frequency[] is storing the number of times each number occurs. So frequency[0] stores the number of times '0' occurs, frequency[1] stores the number of times '1' occurs, and so on.