hello everyone I really need help so I have to make functions that find vowels, digits and uppercase and lowercase letters from a sentence inputted. So i was able to do it all in main but i cant seem to make the new program work with the functions properly, it says on the compiler that it has no errors but ones i debug it, it shoes the wrong answers. would really appreciate the help.
this is what i have so far with the functions
#include <iostream>
#include <cctype>
#include <string>
#include <iomanip>
#include <algorithm>
using namespace std;
int findUpper(char ch); //function to find the uppercase letters in the sentence.
int findLower(char ch); //function to find the lowercase letters in the sentence.
int findDigits(char ch); //function to find the digits in the sentence.
int findVowels(char ch); //function to find the vowels in the sentence.
void display (char ch, int upcount, int lowcount, int digitcount, int vowelcount ); // function that outputs the results.
int main()
{
int upcount; //variable for number of uppercase letters.
int lowcount; //variable for number of lowercase letters
int digitcount; //variable for the number of digits.
int vowelcount; //variable for the number of vowels.
char ch;
//ask user to enter sentence and finds the uppercase letters, lowercase letters, digits and vowels in the sentence.
cout<<"Please enter a sentence. :"<<endl;
cin>>ch;
upcount=findUpper(ch);
lowcount=findLower(ch);
digitcount=findDigits(ch);
vowelcount=findVowels(ch);
display (ch, upcount, lowcount, digitcount, vowelcount );
return 0;
}
int findUpper(char ch)
{
int upcount=0;
while (ch != '\n')
{
if (isupper(ch)) upcount++;
cin.get(ch);
}
return upcount;
}
int findLower(char ch)
{
int lowcount=0;
while (ch != '\n')
{
if (islower(ch)) lowcount++;
cin.get(ch);
}
return lowcount;
}
int findDigits(char ch)
{
int digitcount=0;
while (ch != '\n')
{
if (isdigit(ch)) digitcount++;
cin.get(ch);
}
return digitcount;
}
int findVowels(char ch)
{
int vowelcount=0;
while (ch != '\n')
{
ch=tolower(ch);
if ((ch == 'a')||(ch == 'e')||(ch == 'i')||(ch == 'o')||(ch == 'u')) ++vowelcount;
cin.get(ch);
}
return vowelcount;
}
void display(char ch, int upcount, int lowcount, int digitcount, int vowelcount )
{
cout<<setfill('.');
cout<<left<<setw(24)<<"No. of uppercase letters"
<<right<<setw(10)<<upcount<<endl;
cout<<left<<setw(24)<<"No. of lowercase letters"
<<right<<setw(10)<<lowcount<<endl;
cout<<left<<setw(24)<<"No. of digits letters"
<<right<<setw(10)<<digitcount<<endl;
cout<<left<<setw(24)<<"No. of vowels letters"
<<right<<setw(10)<<vowelcount<<endl;
}
this is without functions which i was able to do but i need to make it into functions
#include <iostream>
#include <cctype>
#include <string>
#include <iomanip>
#include <algorithm>
using namespace std;
int main()
{
int upcount=0, lowcount=0, digitcount=0, vowelcount=0;
char ch;
cout<<"Please enter a sentence. :"<<endl;
cin.get(ch);
while (ch != '\n')
{
if (isupper(ch)) upcount++;
if (islower(ch)) lowcount++;
if (isdigit(ch)) digitcount++;
ch=tolower(ch);
if ((ch == 'a')||(ch == 'e')||(ch == 'i')||(ch == 'o')||(ch == 'u')) ++vowelcount;
cin.get(ch);
}
Thank you to whoever can help me. :D