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
|
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
int largest(){
int num, large = 0;
do {
cout << "Please enter a number. Enter (-1) to quit: ";
cin >> num;
if (large < num)
large = num;
}while(num!= -1);
cout << "Largest Number: " << large;
}
void numberCount(int number, int &oddCount, int &evenCount, int &zeroCount){
const int QUIT = 0;
int aux, digit;
cout << "Enter a number (-1 to exit): ";
cin >> number;
while(number!=-1){
aux = number;
while(aux!=QUIT){
digit = aux % 10;
aux / 10;
if(digit!=0 && digit%2==0){
evenCount++;
}else{if(digit==0)
zeroCount++;
else
oddCount++;
} if(number==0){
zeroCount++;}
}
}
cout << "Even: " << evenCount;
cout << "\nOdd: "<< oddCount;
cout << "\nZero: " << zeroCount;
zeroCount = 0;
evenCount = 0;
oddCount = 0;
cout << "Enter a number (-1 to quit): ";
cin >> number;
}
int main ()
{
int
oddCount = 0,
evenCount = 0,
zeroCount = 0,
number,
digit,
aux;
char choice;
do {
cout << "/nWelcome to my progam!" << endl << endl;
cout << "Here are your following options:" <<endl;
cout << "(a) Find the largest list of positive numbers (-1) to quit" << endl;
cout << "(b) Given a positive number display the number of even, odd, and zero digits in the number" << endl;
cout << "(c) quit the program."<< endl;
cout << "Please enter your choice: ";
cin >> choice;
switch (choice){
case 'a':
largest();
break;
case 'b':
numberCount( number, oddCount, evenCount, zeroCount);
break;
case 'c':
cout << "Thank you for using my program!" << endl;
return 0;
break;
}
}while(choice!='c');
}
|