Guest User

C++ program

a guest
Jun 7th, 2016
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <sstream>
  4. using namespace std;
  5. int main() {
  6.     string line;
  7.     getline(cin, line);
  8.     istringstream input(line);
  9.     int val, sum = 0, count = 0;
  10.     vector<char> v;
  11.     char ch;
  12.     while(input >> ch) {
  13.         v.push_back(ch);
  14. //      cout << ch << " ";
  15.     }
  16.     for(int i = 0 ; i < v.size() ; ++i)
  17.     {
  18.         if(isalpha(v[i])) {
  19.             cout << "Invalid Input" << endl;
  20.             return 0;
  21.             //sum += (v[i] - '0');
  22.         }
  23.         else{
  24.             sum += (v[i] - '0');
  25.         }
  26.     }
  27.     cout << sum << endl;
  28.     return 0;
  29. }
Add Comment
Please, Sign In to add comment