Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int data()
- {
- //A function for calculating numbers of the int type.
- int x = 0, k = 0;
- string text = "ddddd", help;
- getline(cin, help);
- text.insert(0, help);
- for (int i = 0; i < (text.size() - 5); i++)
- {
- if ((47 > text[i]) || (text[i] > 58))
- {
- k += (int)text[i];
- x = k + x;
- }
- else if (((47 < text[i + 5]) && (text[i + 5] < 58)) && ((47 < text[i + 4]) && (text[i + 4] < 58)) && ((47 < text[i + 3]) && (text[i + 3] < 58)) && ((47 < text[i + 2]) && (text[i + 2] < 58)) && ((47 < text[i + 1]) && (text[i + 1] < 58)) && ((47 < text[i]) && (text[i] < 58)))
- {
- x = (text[i] - 48) * 100000 + (text[i + 1] - 48) * 10000 + (text[i + 2] - 48) * 1000 + (text[i + 3] - 48) * 100 + (text[i + 4] - 48) * 10 + (text[i + 5] - 48) + x;
- i += 5;
- }
- else if (((47 < text[i + 4]) && (text[i + 4] < 58)) && ((47 < text[i + 3]) && (text[i + 3] < 58)) && ((47 < text[i + 2]) && (text[i + 2] < 58)) && ((47 < text[i + 1]) && (text[i + 1] < 58)) && ((47 < text[i]) && (text[i] < 58)))
- {
- x = (text[i] - 48) * 10000 + (text[i + 1] - 48) * 1000 + (text[i + 2] - 48) * 100 + (text[i + 3] - 48) * 10 + (text[i + 4] - 48) + x;
- i += 4;
- }
- else if (((47 < text[i + 3]) && (text[i + 3] < 58)) && ((47 < text[i + 2]) && (text[i + 2] < 58)) && ((47 < text[i + 1]) && (text[i + 1] < 58)) && ((47 < text[i]) && (text[i] < 58)))
- {
- x = (text[i] - 48) * 1000 + (text[i + 1] - 48) * 100 + (text[i + 2] - 48) * 10 + (text[i + 3] - 48) + x;
- i += 3;
- }
- else if (((47 < text[i + 2]) && (text[i + 2] < 58)) && ((47 < text[i + 1]) && (text[i + 1] < 58)) && ((47 < text[i]) && (text[i] < 58)))
- {
- x = (text[i] - 48) * 100 + (text[i + 1] - 48) * 10 + (text[i + 2] - 48) + x;
- i += 2;
- }
- else if (((47 < text[i + 1]) && (text[i + 1] < 58)) && ((47 < text[i]) && (text[i] < 58)))
- {
- x = (text[i] - 48) * 10 + (text[i + 1] - 48) + x;
- i++;
- }
- else if ((47 < text[i]) && (text[i] < 58))
- {
- x = (text[i] - 48) + x;
- }
- }
- while (x < 0)
- {
- cout << "Invalid value provided, please re-enter";
- x = data();
- }
- return x;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement