|
My program should take a user inputed paragraph and check for end of sentence marker(i.e. periods, exclamations and question marks), intrasentence markers(i.e. commas, colons, semicolons), blank spaces and digits. Once it checks for these things, it should add up the number of times these things were used and them cout them to the user. My problem is that i cant figure out how to read in the digits or integers and then add them up. I tried using an if statement but that doesn't work and im sure their is more to it. Any help would be much appreciated.
[//This program will recieve user input in the form of a paragraph and //count the number of end sentence markers, intrasentence markers, number of spaces //and the number of digits. It will then output this information to the user.
#include <iostream> #include <limits> using namespace std;
void welcome(); void getYorn(char&);
int main() {
char para; int numUpper = 0; char yorn; int smark = 0; int imark = 0; int blank = 0; int dig = 0; int sum = 0;
welcome(); getYorn(yorn); while (tolower(yorn) == 'y') { cout << "Please enter a paragraph pressing enter when done: "; cin.sync(); for (cin.get(para); para != '\n'; cin.get(para)) { switch (para) { case '.': case '!': case '?': smark++; break; case ',': case ';': case ':': imark++; break; case ' ': blank++; break; } if (para > 0 || para < 0 || para == 0) { dig++; } } cout << endl; cout << "The number of end of sentence markers is: " << smark << endl; cout << "The number of intrasentence markers is: " << imark << endl; cout << "The number of spaces is: " << blank << endl; cout << "The number of digits is: " << dig << endl; getYorn(yorn); smark = 0; imark = 0; blank = 0; dig = 0; } cout << "Thank you - goodbye!" << endl; return 0; }
void welcome() { cout << "Welcome to Ryan's paragraph processing information system." << endl; cout << "This program will calculate the number of end sentence markers, " << endl; cout << "intrasentence markers, number of spaces and number of digits within " << endl; cout << "a paragraph. " << endl << endl;
} void getYorn(char& yorn) { cout << endl; cout << "Do you wish to continue? (y = yes, n = no) : "; cin.sync(); cin.get(yorn); while (tolower(yorn) != 'y' && tolower(yorn) != 'n') { cout << endl; cout << "Invalid response. Do you wish to continue? "; cin.sync(); cin.clear(); cin.get(yorn); } }]
|