#include <iostream> #include <string> using namespace std ; int main() { char str[100] ; // character string max is 100 characters int i ; int upperCase ; int num ; int lowerCase ; 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 ; i = 0 ; while(str[i] != 0) { if ((str[i] >= 'a') && (str[i] <= 'z')) // "i" represents each idividual character that the computer is checking lowerCase++ ; // if "i" is within a-z the computer adds 1 to variable "lowerCase" if ((str[i] >= '0') && (str[i] <= '9')) num++ ; if ((str[i] >= 'A') && (str[i] <= 'Z')) upperCase++ ; i++ ; // tells the computer to continue going through the string while "i" is not 0 } cout << "your string has " << i << " characters" << endl ; cout << "Your string has " << lowerCase << " lowercase letters." << endl ; //prints the number of lowercase characters cout << "Your string has " << num << " numbers in it." << endl ; //prints the number of numbers in the string cout << "Your string has " << upperCase << " uppercase letters." << endl ; //prints the number of uppercase characters cout << "Your string has " << spec << " special characters." << endl ; return 0 ; }
if ... else
if (numbers){ increment number count}else if (lowercase){ increment lowercase count}else if (uppercase){ increment uppercase count}else{ increment specials count}
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)