DasShelmer

7.s.1

Dec 2nd, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int getCharN(char c) {
  6.     if (!isalpha(c))
  7.         return 0;
  8.  
  9.     if (c >= 97)
  10.         c -= 32;
  11.  
  12.     return c - 64;
  13. }
  14.  
  15. long simplify(long n) {
  16.     long result = 0;
  17.     while (n >= 1) {
  18.         result += n % 10;
  19.         n /= 10;
  20.     }
  21.     return result;
  22. }
  23.  
  24. int main() {
  25.     long sum = 0;
  26.  
  27.     cout << "Enter name: ";
  28.     string name = "";
  29.     getline(cin, name);
  30.     for (int i = 0, lenght = name.length(); i < lenght; i++)
  31.         sum += getCharN(name[i]);
  32.    
  33.     while (sum > 9) {
  34.         sum = simplify(sum);
  35.     }
  36.     cout << "Name number is: " << sum << endl;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment