Simple Program

Posts 18 of 8 · Page 1 of 1
Simple Program
Ok, so i am doing problem 5 on project euler (Problem 5 - Project Euler) and i am having trouble. My program works fine, and gives me the correct number. But when i get to a "big" number, it just doesn't print anything on the console. Here is my code (it is very messy and not efficient, but it works, i just wanna throw something together really fast to do the job):

Code:
#include <iostream>

using namespace std;
int numarray[20] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};

void PrintNumber(int number);
int main()
{
    
int number = 1, counter = 0, i = 0, remainder, offset = 0;
    
int remainder0,remainder1,remainder2,remainder3,remainder4,remainder5,remainder6,remainder7,remainder8,remainder9,remainder10,remainder11,remainder12,remainder13,remainder14,remainder15,remainder16,remainder17,remainder18,remainder19,remainder20;
                
  while(1)
   {
   remainder0 = number % numarray[0];
   remainder1 = number % numarray[1];
   remainder2 = number % numarray[2];
   remainder3 = number % numarray[3];
   remainder4 = number % numarray[4];
   remainder5 = number % numarray[5];
   remainder6 = number % numarray[6];
   remainder7 = number % numarray[7];
   remainder8 = number % numarray[8];
   remainder9 = number % numarray[9];
   remainder11 = number % numarray[10];
   remainder12 = number % numarray[11];
   remainder13 = number % numarray[12];
   remainder14 = number % numarray[13];
   remainder15 = number % numarray[14];
   remainder16 = number % numarray[15];
   remainder17 = number % numarray[16];
   remainder18 = number % numarray[17];
   remainder19 = number % numarray[18];
   remainder20 = number % numarray[19];
  
   if(remainder0 == 0 &&
      remainder1 == 0 &&
      remainder2 == 0 &&
      remainder3 == 0 &&
      remainder4 == 0 &&
      remainder5 == 0 &&                                                         
      remainder6 == 0 &&
      remainder7 == 0 &&
      remainder8 == 0 &&
      remainder9 == 0 &&
      remainder11 == 0 &&
      remainder12 == 0 &&
      remainder13 == 0 &&
      remainder14 == 0 &&
      remainder15 == 0 &&
      remainder16 == 0 &&
      remainder17 == 0 &&
      remainder18 == 0 &&
      remainder19 == 0 &&
      remainder20 == 0 ) 
      {
                  
      PrintNumber(number);
                  
      break;
      }
     
           number++;     
   }
      
     
                
  
    
    cin.get();
    return 0;
    
}


void PrintNumber(int number)
{
     cout<<number<<"\n";
}
Thanks in advance.

EDIT=====================================

I did some research and I think that it is just too big of a number for an int type. So i tried unsigned long int and it still doesn't print. IDK if it's just too big or there is another problem. Some ideas on what i could do?






OFF TOPIC: YAY!!! I AM EXPERT MEMBER.
I think i have figured out something. I don't need to include twenty because 4 goes into it, so i don't need to include it in the calculation because if something is divisible by 4 it is by 20 same thing with 5. So i will build on this theory and edit my code and i will see if i get the right answer.

EDIT==========================

Never mind, it's not working like i planned. Any ideas guys?
I JUST SOLVED IT NEVER MIND GUYS.


I used the same code, it just turns out that my program was so inefficient that it took more than like three minutes to get the answer, since i made number go up by only 1. I thought and thought, and then an idea came. In the problem, it tells us that 1 - 10 goes into 2520. So i initialized number as 2520, then i made it increase in each iteration by 2520.

I don't want to say the answer cuz people will cheat, but i basically gave you guys all you need (even though you're probably not doing it, but i am saying it to the people doing these problems.)
C-C-C-COMBO BREAKER.

We all did project euler like ~2 months ago.
Quote Originally Posted by Jason View Post
C-C-C-COMBO BREAKER.

We all did project euler like ~2 months ago.
Oh, well I wish you guys would have told me. It's a really nice website with many good problems that will build you mathematically and help sharpen your programming skills.
Quote Originally Posted by 258456 View Post
Oh, well I wish you guys would have told me. It's a really nice website with many good problems that will build you mathematically and help sharpen your programming skills.
Needa hang in the Coder's Lounge more, I think it was posted there. Wes like...finished the whole thing lol.
Ya i will start going there. And holy crap. Wes finished them? What a genious, there's like 300 of them.
Quote Originally Posted by 258456 View Post
Ya i will start going there. And holy crap. Wes finished them? What a genious, there's like 300 of them.
I don't think he actually completed *all* of them, but most of the difficult ones
Posts 18 of 8 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Need help?