Hi!
I have to write program, that reads signs and it counts, how many is capital letters, how many small letters, and how many remaining signs. It stops, when reads thrue 20 signs or when sign q or Q is entered. Before the end it writes out typed and calculated numbers.
I have some problems with while loop, it doesn't stops by sign q or Q (that is why I put it in comments) and another, bigger problem is with printing all entered numbers on the screen. Do I have to write entered numbers in array or what?
Thanks for your answers!
#include <iostream.h>
#include <stdlib.h>
int main()
{
char sign;
int countersmall, countercapital, counterremain, number, counternumbers, sum;
countersmall = countercapital = counternumbers = sum = 0;
cout << endl << " Program, that reads signs and it counts, how many is capital letters," << endl;
cout << " how many small letters, and how many remaining signs." << endl;
cout << " It stops, when reads thrue 20 signs or when sign q or Q is entered." << endl;
cout << " Before the end it writes out typed and calculated numbers." << endl << endl << endl << endl;
/*
cout << " Enter sign (q or Q for end) and press ENTER: ";
cin >> sign;
if(sign == 'q' || sign == 'Q')
{
cout << endl << endl << endl << " ***** END ***** " << endl;
cout << endl << endl << endl;
system("pause");
return 0;
}
else if(sign != 'q' || sign != 'Q')
do
{
*/
for(int counter = 1; counter <= 20; counter++)
{
cout << endl << " Enter " << counter << ". sign (q or Q for end) and press ENTER: ";
cin >> sign;
if(sign >= 'A' && sign <='Z')
{
countercapital++;
}
if(sign >= '0' && sign <='9')
{
counternumbers++;
if(sign=='0')
{
number=0;
}
else if(sign=='1')
{
number=1;
}
else if(sign=='2')
{
number=2;
}
else if(sign=='3')
{
number=3;
}
else if(sign=='4')
{
number=4;
}
else if(sign=='5')
{
number=5;
}
else if(sign=='6')
{
number=6;
}
else if(sign=='7')
{
number=7;
}
else if(sign=='8')
{
number=8;
}
else if(sign=='9')
{
number=9;
}
else
number=number;
}
if(sign >= 'a' && sign <='z')
{
countersmall++;
}
sum = sum + number;
counterremain = 20 - (counternumbers + countersmall + countercapital);
}
cout << endl << endl << endl << endl << " Number of small letters is: " << countersmall;
cout << endl << " Number of capital letters is: " << countercapital;
cout << endl << " Number of remaining signs is: " << counterremain;
cout << endl << " Number of numbers is: " << counternumbers;
cout << endl << " Sum of all numbers is: " << sum;
cout << endl << " Following numbers were entered:" << endl << " ";
for(counternumbers = 1; counternumbers <= 19; counternumbers++)
{
cout << number << ", ";
}
cout << number;
//}while(sign != 'q' || sign != 'Q');
cout << endl << endl << endl << " ***** END ***** " << endl;
cout << endl << endl << endl << " ";
system("pause");
return 0;
}