I'm writing this program, my instructions are:
Write function that accepts a string as an input then prints out the following:
a. Number of characters in the string excluding spaces
b. Number of letter "a" (small or capital) in the string
c. Number of alphabets in the string
I would like to know if as right now my program is coded as directed, and if you could please
let me know how I would go about doing a and c.
I have spent a big portion of the day trying to lookup examples or info on the net or on this site on how that is done
with no success.
Thank you for your time and help.
#include <iostream> #include <string> #include <cctype> using namespace std; void showValues(string, int); int main() { string sentence; cout << "Enter any sentence you wish and I will tell you the following:\n" << endl; cout << "1. Number of letter A's (small or capital) in the string.\n"; cout << "2. Number of characters in the string excluding spaces.\n"; cout << "3. Number of alphabets in the string.\n" << endl; cout << "Enter sentence now:\n"; getline(cin, sentence); showValues(sentence, sentence.length()); system("pause"); return 0; } void showValues (string chars, int size) { cout << "\nThe string is:"<< endl; for (int index = 0; index < size; index++) cout << chars[index]; cout << endl; // Show how many A's char ch; int vowelCount = 0; for (int pos = 0; pos < size; pos++) { ch=toupper(chars[pos]); switch(ch) { case 'A': vowelCount++; } } cout << "\nThere are " << vowelCount << " A's (small or capital) in the string.\n"; }
This post has been edited by Dark_Nexus: 11 November 2006 - 03:48 PM