http://projecteuler.net/problem=8
Im stuck on this problem, right now im trying to read it into a file and calculate the max from there, but i get some crazy weird output on the console. Can anyone find some problems with my code?
#include <iostream>
#include <fstream>
#define MAX_BOUND 1000 //Array size
void InitArr(char Ar[]); //Set Char
int main()
{
int info;
int POSITION = 5; //Postition of sum(5 number increments)
int SUM = 1; //Resets after every for loop
long MAX,i;
char Arr[MAX_BOUND];
InitArr(Arr);
while(POSITION < 1000)
{
for(i = 0; i < POSITION;i++)
{
int Temp = Arr[i] - '0'; //Removes Ascii coding and leaves it as an integer
SUM = SUM * Temp; //Create sum
}
if(SUM > MAX) //If the sum is more than the current max, then set max to sum.
MAX = SUM;
SUM = 1; //Reset SUM
POSITION += 5; //Add 5 to the position
}
std::cout << "THE MAX IS " << MAX;
}
void InitArr(char Ar[])
{
std::ifstream TextObj("ArrDigits.txt");
for(int i = 0; i < MAX_BOUND; i++)
{
Ar[i] = TextObj.get(); //Grab character and put it into the array
}
TextObj.close(); //Close file
}