if.cpp 544 B

1234567891011121314151617181920212223
  1. // if.cpp -- using the if statement
  2. #include <iostream>
  3. int main()
  4. {
  5. using std::cin; // using declarations
  6. using std::cout;
  7. char ch;
  8. int spaces = 0;
  9. int total = 0;
  10. cin.get(ch);
  11. while (ch != '.') // quit at end of sentence
  12. {
  13. if (ch == ' ') // check if ch is a space
  14. ++spaces;
  15. ++total; // done every time
  16. cin.get(ch);
  17. }
  18. cout << spaces << " spaces, " << total;
  19. cout << " characters total in sentence\n";
  20. // cin.get();
  21. // cin.get();
  22. return 0;
  23. }