Guest User

Untitled

a guest
Jul 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. //NAME : Laura Conley
  2. //GROUP : Hex
  3. //LAST MODIFIED : 4 apr 2012
  4. //PROBLEM ID : Y2K senior program
  5. //DESCRIPTION : Prompts user for 3 numbers, determines how many of each number
  6. //SOURCE/HELPERS : Mr. H.,
  7.  
  8.  
  9. #include <iostream>
  10. #include <string>
  11.  
  12. using namespace std;
  13.  
  14. int main()
  15.  
  16. {
  17.  
  18. //signature
  19.  
  20. cout << "Laura Conley\nHex\nY2K Senior Program\n\n";
  21.  
  22. //Declares name string
  23. string nameStg;
  24.  
  25. int num1, num2, num3, diff, twoCount, currentNum, chopNum, counter, chopDig, numRun;
  26. num1=0;
  27. num2=0;
  28. num3=0;
  29. diff=0;
  30.  
  31. cout << "How many times would you like to run the program?\n ";
  32. cin >> numRun;
  33.  
  34. for (int k=0; k<numRun; k++)
  35. {
  36. int counter[10]=(0);
  37.  
  38. cout << "\n\nEnter the first three numbers of the sequence: ";
  39. cin >> num1 >> num2 >> num3;
  40. diff=num2-num1;
  41. if(num2-num1!=num3-num2)
  42. {
  43. cout << "\nthese numbers are not a sequence. Please try again. ";
  44. }
  45.  
  46.  
  47. currentNum=num1;
  48. int twoCount=0;
  49.  
  50. for (int l=0; l<2000; l++)
  51. {
  52. chopNum=currentNum;
  53. do
  54. {
  55. chopDig=abs(currentNum%10);
  56. counter[chopDig]++;
  57. chopNum/=10;
  58. } while(chopNum!=0);
  59. currentNum+=diff;
  60. }
  61.  
  62. for (int h=0; h<10; h++)
  63. {
  64. cout << h << ":" << counter[h] << "\n";
  65. }
  66.  
  67. //Finds the most common number
  68. big=counter[0];
  69.  
  70. for(int q=0;q<10;q++)
  71.  
  72. {
  73.  
  74. if(counter[q]>big)
  75.  
  76. {
  77.  
  78. big=counter[q];
  79.  
  80. }
  81.  
  82. }
  83.  
  84. Cout << "\nModal number is/are: "
  85. (for int x=0; x<10; x++)
  86. {
  87. if (counter[x]==big)
  88. {
  89. cout << x << " ";
  90. }
  91. }
  92.  
  93. return 0;
  94. }
Add Comment
Please, Sign In to add comment