Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. //CSIT 121
  2. //Dr. Straight
  3. //Programming Assignment 1
  4.  
  5. //Program written by Salvatore Barone
  6.  
  7. #include <iostream>
  8. #include <iomanip>
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. //Variables used:
  14. int n; //Positive integer used to compute the orbit function
  15. int response; //Response to iterations question
  16.  
  17. //Input n
  18. cout << “Please enter a positive integer“ << endl;
  19. cin >> n;
  20. while (n > 1)
  21. {
  22. cout << “Would you like to see iterations of your function? (Enter Y or N)” << end;
  23. cin << response;
  24. if (response == ‘Y’)
  25. {
  26. length = orbit (n);
  27. cout << “The length of your orbit is: “ << length;
  28. cout << “The iterations of your orbit are: “ << endl;
  29. cout << setw(length) << endl;
  30.  
  31. }
  32. else if (response == 'N')
  33. {
  34. //Calculate Orbit
  35. length = orbit (n);
  36. cout << “The length of your orbit is: “ << length;
  37. }
  38. cout << “Enter another integer, or 0 to quit” << endl;
  39. cin >> n;
  40. }
  41. system("pause");
  42. return 0;
  43. }
  44.  
  45. int orbit(int n)
  46.  
  47. {
  48.  
  49. While (length > 1)
  50. {
  51. int length; //the number of terms in the sequence up to, but excluding, the first .
  52. if (n % 2 == 0) n = n/2;
  53. if (n % 2 == 1) n = 3*n + 1;
  54. length = length + 1;
  55. return length;
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement