Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int getCharN(char c) {
- if (!isalpha(c))
- return 0;
- if (c >= 97)
- c -= 32;
- return c - 64;
- }
- long simplify(long n) {
- long result = 0;
- while (n >= 1) {
- result += n % 10;
- n /= 10;
- }
- return result;
- }
- int main() {
- long sum = 0;
- cout << "Enter name: ";
- string name = "";
- getline(cin, name);
- for (int i = 0, lenght = name.length(); i < lenght; i++)
- sum += getCharN(name[i]);
- while (sum > 9) {
- sum = simplify(sum);
- }
- cout << "Name number is: " << sum << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment