| pizzlefank (1) | |
|
Hello I am new. I need to write a program using at least one while loop to count and display the amount of vowels in a user input string. This is what I have so far. #include <iostream> #include <cmath> using namespace std; int main() { int acounter(0); // Create counters for each vowel int ecounter(0); int icounter(0); int ocounter(0); int ucounter(0); char c; // Set variable c as a character cout << "Input: "; // Let user declare c cin >> c; while (c) // Run loop to count vowels { if (c == 'a'|| c== 'A') { acounter = acounter + 1; } if (c == 'e'|| c== 'E') { ecounter = ecounter + 1; } if (c == 'i'|| c== 'I') { icounter = icounter + 1; } if (c == 'o'|| c== 'O') { ocounter = ocounter + 1; } if (c == 'u'|| c== 'U') { ucounter = ucounter + 1; } } cout << acounter; cout << ecounter; cout << icounter; cout << ocounter; cout << ucounter; return 0; } I don't have a clue where to go. Please help a newbie. Explanation would be helpful. Thanks | |
|
|
|
| Smac89 (195) | |
|
get word from user if (toupper (word[i]) == 'A' || toupper (word[i]) == 'E' || toupper (word[i]) == 'I' || toupper (word[i]) == 'O' || toupper (word[i]) == 'U') increment counter | |
|
|
|
| vlad from moscow (3650) | |||
This
is invalid code. I think you have to use a character array instead of one character. | |||
|
Last edited on
|
|||