legionaire45
October 3rd, 2008, 03:38 AM
I just sat down and finished Problem 1 (http://projecteuler.net/).
It took me 2 or so hours.
BUT I BEAT THIS DERP.
/*
Morgan Cabral - 10/02/08
Project Euler - Problem 1
Header File
*/
#ifndef PROBLEM_1_H
#define PROBLEM_1_H
// Function Blueprints
int findTotalMultiples ( int base, int threshold); // Finds the total of all of the multiples
// of the supplied number combined up until
// the supplied threshold value.
#endif // PROBLEM_1_H
/*
Morgan Cabral - 10/02/08
Project Euler - Problem 1
Source File
*/
#include <iostream> // Standard Library
#include "problem_1.h" // Custom Header w/ Function Blueprints
using namespace std;
// Main Function
int main()
{
// Constants
const int THRESHOLD_NUMBER = 1000; // The number that all multiples must be lower than.
// Variables
int finalTotal = 0; // The final total value.
// Math
finalTotal = findTotalMultiples ( 3, THRESHOLD_NUMBER ) // Add the total of all of the multiples of three
+ findTotalMultiples ( 5, THRESHOLD_NUMBER ); // to that of all of the multiples of five.
cout << "The total of all of the multiples of 3 and 5 is: " // Print the answer to the console.
<< finalTotal << endl;
int theTest = 0; // D E B U G
cin >> theTest;
return 0;
}
/*
Morgan Cabral - 10/02/08
Project Euler - Problem 1
Source File
*/
// Headers
#include <iostream>
#include "problem_1.h"
using namespace std;
/*********************************************
Function Declaration - int findTotalMultiples
This function calculates the sum of
all of the multiples of the number
given via "base" up until the
"threshold" number.
*********************************************/
int findTotalMultiples ( int base, int threshold )
{
int i = 0; // Counter.
int currentMultiple = 0; // The current multiple to add to the subtotal.
int subTotal = 0; // The combined value of all the currently
// calculated multiples.
while ( currentMultiple < threshold - base % threshold )
/* While currentMultiple is less then the threshold minus
the remainder of base modulo threshold... */
{
i++; // Iterate the counter...
currentMultiple = base * i; // Calculate the current multiple...
subTotal += currentMultiple; // Add that to the subtotal...
/* cout << base << " x " << i // D E B U G - print out info
<< " = " // Uncomment to get a printout
<< currentMultiple // In the console.
<< endl; */
}
return subTotal;
}
Plz comment on my shitty coding skills, lulz.
It took me 2 or so hours.
BUT I BEAT THIS DERP.
/*
Morgan Cabral - 10/02/08
Project Euler - Problem 1
Header File
*/
#ifndef PROBLEM_1_H
#define PROBLEM_1_H
// Function Blueprints
int findTotalMultiples ( int base, int threshold); // Finds the total of all of the multiples
// of the supplied number combined up until
// the supplied threshold value.
#endif // PROBLEM_1_H
/*
Morgan Cabral - 10/02/08
Project Euler - Problem 1
Source File
*/
#include <iostream> // Standard Library
#include "problem_1.h" // Custom Header w/ Function Blueprints
using namespace std;
// Main Function
int main()
{
// Constants
const int THRESHOLD_NUMBER = 1000; // The number that all multiples must be lower than.
// Variables
int finalTotal = 0; // The final total value.
// Math
finalTotal = findTotalMultiples ( 3, THRESHOLD_NUMBER ) // Add the total of all of the multiples of three
+ findTotalMultiples ( 5, THRESHOLD_NUMBER ); // to that of all of the multiples of five.
cout << "The total of all of the multiples of 3 and 5 is: " // Print the answer to the console.
<< finalTotal << endl;
int theTest = 0; // D E B U G
cin >> theTest;
return 0;
}
/*
Morgan Cabral - 10/02/08
Project Euler - Problem 1
Source File
*/
// Headers
#include <iostream>
#include "problem_1.h"
using namespace std;
/*********************************************
Function Declaration - int findTotalMultiples
This function calculates the sum of
all of the multiples of the number
given via "base" up until the
"threshold" number.
*********************************************/
int findTotalMultiples ( int base, int threshold )
{
int i = 0; // Counter.
int currentMultiple = 0; // The current multiple to add to the subtotal.
int subTotal = 0; // The combined value of all the currently
// calculated multiples.
while ( currentMultiple < threshold - base % threshold )
/* While currentMultiple is less then the threshold minus
the remainder of base modulo threshold... */
{
i++; // Iterate the counter...
currentMultiple = base * i; // Calculate the current multiple...
subTotal += currentMultiple; // Add that to the subtotal...
/* cout << base << " x " << i // D E B U G - print out info
<< " = " // Uncomment to get a printout
<< currentMultiple // In the console.
<< endl; */
}
return subTotal;
}
Plz comment on my shitty coding skills, lulz.