Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. /**
  2. *
  3. * Solution to homework task 2
  4. * Introduction to programming course
  5. * Faculty of Mathematics and Informatics of Sofia University
  6. * Winter Semester 2018/2019
  7. *
  8. * @author Andrey Kirilov Stoev
  9. * @idnumber 62369
  10. * @task 2
  11. * @compiler VC
  12. */
  13.  
  14. #include <iostream>
  15. #include <string>
  16. using namespace std;
  17.  
  18. int main()
  19. {
  20.  
  21. int number;
  22. short digit;
  23. cout << "Enter a natural number: " << endl;
  24.  
  25. while (!(cin >> number))
  26. {
  27. cin.clear(); // reset input
  28. while (cin.get() != '\n')
  29. continue; // get rid of bad input
  30. cout << "Please enter an integer number, that doesn't work: " << endl;
  31. }
  32.  
  33. cout << "Enter a digit: " << endl;
  34.  
  35. while (!(cin >> digit))
  36. {
  37. cin.clear(); // reset input
  38. while (cin.get() != '\n')
  39. continue; // get rid of bad input
  40. cout << "Please enter a digit, that doesn't work: " << endl;
  41. }
  42.  
  43. int counter = 0;
  44.  
  45. while (number != 0)
  46. {
  47. if (number % 10 == digit)
  48. {
  49. counter++;
  50. }
  51. number /= 10;
  52. }
  53. cout << "The number of occurrences of the digit in the number is: " << counter;
  54.  
  55. int variableForWindowClosing;
  56. cin >> variableForWindowClosing;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement