fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. int main()
  5. {
  6. using std::cout;
  7. using std::cin;
  8. using std::getline; //I assume you want spaces in your sentences
  9. using std::string; // can you use std::string? Or only char arrays/chars?
  10. using std::endl;
  11.  
  12.  
  13. string setence , vowels = "";
  14. int numVowels = 0;
  15.  
  16. cout << "Please enter a setence: ";
  17. getline( cin , setence );
  18.  
  19. for( int i = 0; setence[i]; ++i ) //loop while it is not a null character
  20. {
  21. switch( toupper(setence[i]) )
  22. {
  23. case 'A': case 'E': case 'I': case 'O': case 'U': //some times y?
  24. ++numVowels;
  25. vowels += setence[i];
  26. }
  27. }
  28.  
  29. cout << "Number of vowels: " << numVowels << endl;
  30. cout << "Vowels used are: " << vowels << endl;
  31. }
Success #stdin #stdout 0s 3432KB
stdin
This is a test string being entered.
stdout
Please enter a setence: Number of vowels: 10
Vowels used are: iiaeieieee