Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //NAME : Laura Conley
- //GROUP : Hex
- //LAST MODIFIED : 4 apr 2012
- //PROBLEM ID : Y2K senior program
- //DESCRIPTION : Prompts user for 3 numbers, determines how many of each number
- //SOURCE/HELPERS : Mr. H.,
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- //signature
- cout << "Laura Conley\nHex\nY2K Senior Program\n\n";
- //Declares name string
- string nameStg;
- int num1, num2, num3, diff, twoCount, currentNum, chopNum, counter, chopDig, numRun;
- num1=0;
- num2=0;
- num3=0;
- diff=0;
- cout << "How many times would you like to run the program?\n ";
- cin >> numRun;
- for (int k=0; k<numRun; k++)
- {
- int counter[10]=(0);
- cout << "\n\nEnter the first three numbers of the sequence: ";
- cin >> num1 >> num2 >> num3;
- diff=num2-num1;
- if(num2-num1!=num3-num2)
- {
- cout << "\nthese numbers are not a sequence. Please try again. ";
- }
- currentNum=num1;
- int twoCount=0;
- for (int l=0; l<2000; l++)
- {
- chopNum=currentNum;
- do
- {
- chopDig=abs(currentNum%10);
- counter[chopDig]++;
- chopNum/=10;
- } while(chopNum!=0);
- currentNum+=diff;
- }
- for (int h=0; h<10; h++)
- {
- cout << h << ":" << counter[h] << "\n";
- }
- //Finds the most common number
- big=counter[0];
- for(int q=0;q<10;q++)
- {
- if(counter[q]>big)
- {
- big=counter[q];
- }
- }
- Cout << "\nModal number is/are: "
- (for int x=0; x<10; x++)
- {
- if (counter[x]==big)
- {
- cout << x << " ";
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment