fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std ;
  4.  
  5. int main()
  6. {
  7. char str[100] = {0}; // available character string max is 99 characters
  8. int i = 0;
  9. int lett = 0;
  10. int num = 0;
  11. int spec = 0;
  12.  
  13. cout << "Please enter a continuous string of characters with no spaces" << endl ;
  14. cout << "(example: ASO@23iow$)" << endl << endl ; //shows an example and then adds a blank line
  15. cout << "Enter your string: " ;
  16. cin >> str ;
  17. cout << endl ;
  18.  
  19. while(str[i] != 0)
  20. {
  21. cout << "<" << str[i] << ">";
  22. switch(str[i])
  23. {
  24. case '0' ... '9':
  25. cout << " num" << endl;
  26. i++;
  27. num++;
  28. break ;
  29. case 'a' ... 'z':
  30. cout << " letl" << endl;
  31. i++;
  32. lett++;
  33. break ;
  34. case 'A' ... 'Z':
  35. cout << " letu" << endl;
  36. i++;
  37. lett++;
  38. break ;
  39. default :
  40. cout << " up" << endl;
  41. i++;
  42. spec++;
  43. }
  44. }
  45.  
  46. cout << "your string has " << i << " characters" << endl ;
  47. //prints the number of numbers in the string
  48. cout << "Your string has " << num << " numbers in it." << endl ;
  49. cout << "Your string has " << lett << " letters in it." << endl ;
  50. cout << "Your string has " << spec << " special characters." << endl ;
  51. return 0 ;
  52. }
Success #stdin #stdout 0s 3476KB
stdin
qwfqwef%#$%635477erg
stdout
Please enter a continuous string of characters with no spaces
(example: ASO@23iow$)

Enter your string: 
<q> letl
<w> letl
<f> letl
<q> letl
<w> letl
<e> letl
<f> letl
<%> up
<#> up
<$> up
<%> up
<6> num
<3> num
<5> num
<4> num
<7> num
<7> num
<e> letl
<r> letl
<g> letl
your string has 20 characters
Your string has 6 numbers in it.
Your string has 10 letters in it.
Your string has 4 special characters.