1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
#include "Lab10_Exercise2.h"
#include <iostream>
#include <string>
using namespace std;
int storenumber ( int [], const int, int, int, int, int, int, int, int, int, int, int, int );
void countduplicatenumbers (int, int, int, int, int, int, int, int, int, int);
int main()
{
const int SIZE = 100;
int onedigitnum[SIZE];
int count = 0;
int number;
int Zero = 0, One = 0, Two = 0, Three = 0, Four = 0, Five = 0, Six = 0, Seven = 0, Eight = 0, Nine = 0;
cout << "Enter a one-digit number or 10 to exit: ";
cin >> number;
while ( number != 10 && count < SIZE)
{
if ( number >= 0 && number <= 9 )
{
count++;
onedigitnum[count - 1] = number;
storenumber ( onedigitnum, SIZE, count, Zero, One, Two, Three, Four, Five, Six, Seven, Eight, Nine );
cout << "Enter a one-digit number or 10 to exit: ";
cin >> number;
}
else
{
cout << "You've entered in an in valid number." << endl;
cout << "Enter a one-digit number or 10 to exit: ";
cin >> number;
}
}
countduplicatenumbers ( Zero, One, Two, Three, Four, Five, Six, Seven, Eight, Nine);
cout << endl << endl;
return 0;
}
int storenumber ( int usernumber[], const int size, int count, int countZero, int countOne, int countTwo, int countThree, int countFour, int countFive, int countSix, int countSeven, int countEight, int countNine)
{
for (int index = 0; index <= count; index++)
{
if ( usernumber[index] == 0)
{
++countZero;
}
else if ( usernumber[index] == 1)
{
++countOne;
}
else if ( usernumber[index] == 2)
{
++countTwo;
}
else if ( usernumber[index] == 3)
{
++countThree;
}
else if ( usernumber[index] == 4)
{
++countFour;
}
else if ( usernumber[index] == 5)
{
++countFive;
}
else if ( usernumber[index] == 6)
{
++countSix;
}
else if ( usernumber[index] == 7)
{
++countSeven;
}
else if ( usernumber[index] == 8)
{
++countEight;
}
else if ( usernumber[index] == 9)
{
++countNine;
}
return countZero, countOne, countTwo, countThree, countFour, countFive, countSix, countSeven, countEight, countNine;
}
}
void countduplicatenumbers (int Zero, int One, int Two, int Three, int Four, int Five, int Six, int Seven, int Eight, int Nine)
{
cout << "You've entered " << Zero << " 0 (s)" << endl;
cout << "You've entered " << One << " 1 (s)" << endl;
cout << "You've entered " << Two << " 2 (s)" << endl;
cout << "You've entered " << Three << " 3 (s)" << endl;
cout << "You've entered " << Four << " 4 (s)" << endl;
cout << "You've entered " << Five << " 5 (s)" << endl;
cout << "You've entered " << Six << " 6 (s)" << endl;
cout << "You've entered " << Seven << " 7 (s)" << endl;
cout << "You've entered " << Eight << " 8 (s)" << endl;
cout << "You've entered " << Nine << " 9 (s)" << endl;
}
|