This is what i have so far. I was told to use the cin.get() function in order to read in a character one at a time in order to count the number of characters inputed. I dont think i used it right and after i input a paragraph the program just freezes up. The parameters of this project are to exclude white spaces from the count and end when the loop reaches the return key. Any help would be greatly appreciated.
CODE
#include<iostream>
#include<string>
using namespace std;
int main()
{
char para;
char yorn;
int counter = 0;
cout << "Welcome to Ryan's Character Counter program! This program will allow you to" << endl;
cout << "enter any size paragraph and will return the number of characters in that" << endl;
cout << "paragraph. You will enter a paragraph and when finished, press enter. At" << endl;
cout<< "that time, the program will calculate the number of characters entered, print" << endl;
cout<< "out that value and ask you if you wish to continue." << endl << endl;
cout << "Do you wish to continue? (y = yes, n = no): ";
cin >> yorn;
yorn = tolower(yorn);
while (yorn != 'y' && yorn != 'n')
{
cout << "Invalid response, do you wish to continue? (y = yes, n = no): ";
cin.sync();
cin >> yorn;
}
if (yorn == 'n')
return 0;
while (yorn == 'y')
{
system("cls");
cout << "Enter the paragraph - ";
cin.sync();
cin.clear();
cin.get(para);
while (para != '\n')
{
if (para != ' ')
{
counter += para;
}
}
cout << "The number of nonblank characters is: " << counter << endl;
return (0);
}
}
edit: Code placed in code tags - Martyr2
This post has been edited by Martyr2: 7 Nov, 2007 - 02:09 PM