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

First things first.

You must use array of storing sentences or string datatype.

Line 24 : Its simply takes the first character of you input.

ok thanks for the help but i actually got it now

#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=0; //variable for number of uppercase letters.
int lowcount=0; //variable for number of lowercase letters
int digitcount=0; //variable for the number of digits.
int vowelcount=0; //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.get(ch); 
    while (ch != '\n') 
    {
        upcount += findUpper(ch);
        lowcount += findLower(ch);
        digitcount += findDigits(ch);
        vowelcount += findVowels(ch);
        cin.get(ch);
    }  
    display (ch, upcount, lowcount, digitcount, vowelcount );

return 0;
}

int findUpper(char ch)
{
// return 1 if the charater is upper case. Else return 0. 
    if (isupper(ch)) return 1; 
    return 0;
} //End findupper() 



int findLower(char ch)
{ 
    if(islower(ch)) return 1; 
    return 0; 
}

int findDigits(char ch)
{
//int digitcount=0;

if (isdigit(ch)) return 1;
return 0;
}

int findVowels(char ch)
{
//int vowelcount=0;

ch=tolower(ch);
if ((ch == 'a')||(ch == 'e')||(ch == 'i')||(ch == 'o')||(ch == 'u')) return 1;
return 0; 
}

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;
} 

now it works perfectly

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.