Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7.  
  8. bool isPrime(int n){
  9. int test;
  10. for (test = 2; test < sqrt(n); test++){
  11. if (n % test == 0){
  12. return false;
  13. }//endif
  14. }//endfor
  15. return true;
  16. }
  17.  
  18. int getNextPrime(int minimum){
  19. do {
  20.  
  21. minimum = minimum++;
  22. cout << "The value of minimum is now: " << minimum << endl;
  23. }while (isPrime(minimum) == false);
  24.  
  25. return minimum ;
  26. }
  27.  
  28.  
  29.  
  30. void printSolution (int n, bool isRear){
  31. if (isRear == true){
  32. cout << n << " is a candidate for the rear gear" << endl;
  33. }else {
  34. cout << n << " is a candidate for the front gear" << endl;
  35. }//endif
  36. }
  37.  
  38.  
  39. int main (void) {
  40.  
  41. // Constants
  42. const int lowestGear = 8,
  43. numberOfRearGears = 7,
  44. numberOfFrontGears = 3,
  45. numberOfGears = 10;
  46.  
  47. // Variables
  48. int currentCheck = lowestGear,
  49. countRear = 0,
  50. countFront = 0,
  51. countTot = 0,
  52. previousPrime = 0,
  53. test, // 'test' value to see if they evenly divide by 'currentCheck' (and therefore not prime)
  54. sqrtCC; // a place to store the squareRoot of 'currentCheck', so we only need to calculate only once.
  55. bool isRear,
  56. result;
  57.  
  58. // Iterate through a series of prime numbers
  59. do {
  60. getNextPrime(currentCheck);
  61. if(countRear < numberOfRearGears){
  62. isRear = true;
  63. countRear=countRear+1;
  64. } else {
  65. isRear = false;
  66. countFront=countFront+1;
  67. }//endif
  68. printSolution(currentCheck,isRear);
  69. countTot = countRear + countFront;
  70. } while (countTot < numberOfGears);
  71.  
  72. system("PAUSE"); return 0;
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement