***NOT WORKING - CIN NOT WORKING - GETLINE NOT WORKING - THANKS - READING IN A S
ID: 3787580 • Letter: #
Question
***NOT WORKING - CIN NOT WORKING - GETLINE NOT WORKING - THANKS - READING IN A SENTENCE OF USER SELECTED SIZE THANKS C++
#include <iostream>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <iomanip>
using namespace std;
void displaymenu();
int count_vowels(char *, int);
int main()
{
int Size;
cout << "Enter size of sentence: " << endl;
cin >> Size;
char phrase[Size];
int num_vowels =0;
//Input a string
cout << "Enter a sentence : .................";
cin.getline(phrase, Size);
cout << "/......................../" << endl;
cout << "Your sentence : ............. ";
cout << phrase << endl;
char choice;
do
{
displaymenu();
cin >> choice;
switch(choice)
{
case 'A':
case 'a':
cout << "Count the number of vowels in the string: " << endl;
num_vowels =count_vowels(phrase, Size);;
cout << "The number of vowels: .................... " << num_vowels << endl;
break;
default:
{
cout << "You didn't enter A,B,C,D, or E: Please re-start program" << endl;
}
}
}while(choice == 'D' || choice <= 'F');
return 0;
}
void displaymenu()
{
cout << "/......................../" << endl;
cout << "Menu:" << endl;
cout << "Enter A: Count the number of vowels in the string: " << endl;
cout << "Enter B: Count the number of consonants in the string: " << endl;
cout << "Enter C: Count Both the vowels and consonants in the string: " << endl;
cout << "Enter D: Enter another string: " << endl;
cout << "Enter E: Exit the program: " << endl;
}
int count_vowels(char *charptr, int amount) //function
{
int counter = 0;
while(*charptr!='')
{
if(*charptr == 'a' || *charptr == 'e' || *charptr == 'i' || *charptr == 'o' || *charptr == 'u')
{
counter++;
charptr++;
}
}
return counter;
}
Explanation / Answer
I have debug your code at my end it is working fine,.
Please run your code on online compiler http://cpp.sh/.
Please let us know where are running your code.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.