PracticeDev/study_cpp/cpp_primer_source_code/Chapter 6/if.cpp

24 lines
567 B
C++
Raw Permalink Normal View History

2022-12-20 17:31:11 +08:00
// if.cpp -- using the if statement
#include <iostream>
int main()
{
using std::cin; // using declarations
using std::cout;
char ch;
int spaces = 0;
int total = 0;
cin.get(ch);
while (ch != '.') // quit at end of sentence
{
if (ch == ' ') // check if ch is a space
++spaces;
++total; // done every time
cin.get(ch);
}
cout << spaces << " spaces, " << total;
cout << " characters total in sentence\n";
// cin.get();
// cin.get();
return 0;
}