1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
// Check line.cpp : main project file.
#include <string>
#include <iostream>
using namespace std;
int main()
{
string line;
int num;
int plussign = 0, negsign=0, commasign=0, periodsign;
do
{
plussign = 0, negsign=0, commasign=0, periodsign = 0; // Zero out the variables
cout << "enter a line with '+', '-', '.' and ',' in it" << endl;
getline(cin,line);
num = line.length();
for(int x=0;x<num;x++)
{
if (line[x] == '+')
plussign++;
if (line[x] == '-')
negsign++;
if (line[x] == ',')
commasign++;
if (line[x] == '.')
periodsign++;
}
if( num >0) // Print out line only if something was entered
cout << "You had " << plussign << " plus signs, " << negsign << " minus signs, " << periodsign << " periods and " << commasign << " commas.." << endl << endl;
} while (num > 0);
}
|