Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- #include <cstdlib>
- using namespace std;
- bool isPrime(int n){
- int test;
- for (test = 2; test < sqrt(n); test++){
- if (n % test == 0){
- return false;
- }//endif
- }//endfor
- return true;
- }
- int getNextPrime(int minimum){
- do {
- minimum = minimum++;
- cout << "The value of minimum is now: " << minimum << endl;
- }while (isPrime(minimum) == false);
- return minimum ;
- }
- void printSolution (int n, bool isRear){
- if (isRear == true){
- cout << n << " is a candidate for the rear gear" << endl;
- }else {
- cout << n << " is a candidate for the front gear" << endl;
- }//endif
- }
- int main (void) {
- // Constants
- const int lowestGear = 8,
- numberOfRearGears = 7,
- numberOfFrontGears = 3,
- numberOfGears = 10;
- // Variables
- int currentCheck = lowestGear,
- countRear = 0,
- countFront = 0,
- countTot = 0,
- previousPrime = 0,
- test, // 'test' value to see if they evenly divide by 'currentCheck' (and therefore not prime)
- sqrtCC; // a place to store the squareRoot of 'currentCheck', so we only need to calculate only once.
- bool isRear,
- result;
- // Iterate through a series of prime numbers
- do {
- getNextPrime(currentCheck);
- if(countRear < numberOfRearGears){
- isRear = true;
- countRear=countRear+1;
- } else {
- isRear = false;
- countFront=countFront+1;
- }//endif
- printSolution(currentCheck,isRear);
- countTot = countRear + countFront;
- } while (countTot < numberOfGears);
- system("PAUSE"); return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement