My task is to get a string with no spaces from the user and make the computer count the number of characters, letters, numbers, and special characters (i.e. !@#$%^&*) However the program seems to be skipping the first character no matter what category this character falls under. note that it does count it in the number of characters just not in its category example: cin >> aZ12!@
output: 6 characters, 1 letter, 2 numbers, 2 special characters. it always skips the first character.
#include <iostream>
#include <string>
using namespace std;
int main()
{
char str[100]; // available character string max is 99 characters
int i;
int lett;
int num;
int spec;
cout << "Please enter a continuous string of characters with no spaces" << endl ;
cout << "(example: ASO@23iow$)" << endl << endl ; //shows an example and then adds a blank line
cout << "Enter your string: " ;
cin >> str ;
cout << endl ;
while(str[i] != 0)
{
switch(str[i])
{
case '0' ... '9':
i++ && num++;
break ;
case 'a' ... 'z':
i++ && lett++;
break ;
case 'A' ... 'Z':
i++ && lett++;
break ;
default :
i++ && spec++;
}
}
cout << "your string has " << i << " characters" << endl ;
//prints the number of numbers in the string
cout << "Your string has " << num << " numbers in it." << endl ;
cout << "Your string has " << lett << " letters in it." << endl ;
cout << "Your string has " << spec << " special characters." << endl ;
return 0 ;
'0' ... '9'
is not standard C++ and b) you need to enable more compiler warnings.