Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * Solution to homework task 2
- * Introduction to programming course
- * Faculty of Mathematics and Informatics of Sofia University
- * Winter Semester 2018/2019
- *
- * @author Andrey Kirilov Stoev
- * @idnumber 62369
- * @task 2
- * @compiler VC
- */
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- int number;
- short digit;
- cout << "Enter a natural number: " << endl;
- while (!(cin >> number))
- {
- cin.clear(); // reset input
- while (cin.get() != '\n')
- continue; // get rid of bad input
- cout << "Please enter an integer number, that doesn't work: " << endl;
- }
- cout << "Enter a digit: " << endl;
- while (!(cin >> digit))
- {
- cin.clear(); // reset input
- while (cin.get() != '\n')
- continue; // get rid of bad input
- cout << "Please enter a digit, that doesn't work: " << endl;
- }
- int counter = 0;
- while (number != 0)
- {
- if (number % 10 == digit)
- {
- counter++;
- }
- number /= 10;
- }
- cout << "The number of occurrences of the digit in the number is: " << counter;
- int variableForWindowClosing;
- cin >> variableForWindowClosing;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement