relpy thanks

I am stuck I cant run my code I need help!!! thanks
#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <stdio.h>
#include <cctype>
using namespace std;

bool isVowel(char c)
{
bool VowelStr = "";
const string vowels = "aAeEiIoOuU";
vowels.find(c) != string::npos;

return c;
}

bool isPunctuationMark(char c)
{
int n;
int count =0;
char str[]="Hello, welcome!";
for ( n=0 ; str[n]!='' ; n++)
{
if(ispunct(str[n])!=0)
count++;
}
printf ("Array has %d punctuations.\n", count);
return 0;
}

int main()
{
string line;
int vowels, consonants, digits, spaces;

vowels = consonants = digits = spaces = 0;

cout << cout << "Enter a string: ";

getline(cin, line);

for(int i = 0; i < line.length(); ++i)
{
if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
line[i]=='o' || line[i]=='u' || line[i]=='A' ||
line[i]=='E' || line[i]=='I' || line[i]=='O' ||
line[i]=='U')
{
++vowels;
}
else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
{
++consonants;
}
else if(line[i]>='0' && line[i]<='9')
{
++digits;
}
else if (line[i]==' ')
{
++spaces;
}
}
{


cout << " " << endl;

cout << "Total count of letter<s> is" << " with " << endl;
cout << setw(8) << " upper case letter<s>" << endl;
cout << setw(8) << " lower case letter<s>" << endl;
cout << setw(8) << vowels << " vowel<s>" << endl;
cout << setw(8) << consonants << " consonant<s> " << endl;
cout << " " << endl;
cout << " Total count of digit<s> is " << digits << endl;
cout << " " << endl;
cout << " Toatal count of punctuation marks<s> is " << endl;
cout << " " << endl;
cout << " Total count of whitespace<s> is " << spaces << endl;
cout << " " << endl;
cout << " The reverse string: ";



return 0;
}
Could you please edit your post and put your code in code blocks and give it proper indentation so that it is easier to read. Also let us know what you want your code to do and what specific problems you are running into. You are more likely to get people to help you if you don't force them to dig through your code and try and figure out what you are trying to accomplish.
So now I am stuck on getting the uppercase, lowercase letters, and Punctuation to be counted of the string I entered.

sorry how do you use the blocks????? its because im new
I've not checked your code works, but there is a syntax error.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <stdio.h>
#include <cctype>
using namespace std;

bool isVowel(char c)
{
bool VowelStr = "";
const string vowels = "aAeEiIoOuU";
vowels.find(c) != string::npos;

return c;
}

bool isPunctuationMark(char c)
{
int n;
int count =0;
char str[]="Hello, welcome!";
for ( n=0 ; str[n]!='' ; n++)
{
if(ispunct(str[n])!=0)
count++;
}
printf ("Array has %d punctuations.\n", count);
return 0;
}

int main()
{
string line;
int vowels, consonants, digits, spaces;

vowels = consonants = digits = spaces = 0;

cout << cout << "Enter a string: ";

getline(cin, line);

for(int i = 0; i < line.length(); ++i)
{
if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
line[i]=='o' || line[i]=='u' || line[i]=='A' ||
line[i]=='E' || line[i]=='I' || line[i]=='O' ||
line[i]=='U')
{
++vowels;
}
else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
{
++consonants;
}
else if(line[i]>='0' && line[i]<='9')
{
++digits;
}
else if (line[i]==' ')
{
++spaces;
}
}

{/*******************************
       WRONG WAY ROUND AND NOT NEEDED
       *******************************/
cout << " " << endl;

cout << "Total count of letter<s> is" << " with " << endl;
cout << setw(8) << " upper case letter<s>" << endl;
cout << setw(8) << " lower case letter<s>" << endl;
cout << setw(8) << vowels << " vowel<s>" << endl;
cout << setw(8) << consonants << " consonant<s> " << endl;
cout << " " << endl;
cout << " Total count of digit<s> is " << digits << endl;
cout << " " << endl;
cout << " Toatal count of punctuation marks<s> is " << endl;
cout << " " << endl;
cout << " Total count of whitespace<s> is " << spaces << endl;
cout << " " << endl;
cout << " The reverse string: ";



return 0;
}
Last edited on
Use these functions:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
std::string reverse(const std::string &s)
{
    return std::string(s.crbegin(), s.crend());
}

bool isVowel(char c)
{
    const std::string vowels = "aAeEiIoOuU";
    return vowels.find(c) != std::string::npos;
}

bool isPunct(char c)
{
    const std::string punct = "+=%₩<>!@#~/^&*()-\'\":;,\?`_\\|{}[]$€£¥";
    return punct.find(c) != std::string::npos;
}
thank you I already try that but it doesn't work
Then, you're using the functions wrong. Or not calling them right. You call functions like this:

function_name(arguments)
Last edited on
Example use of the functions above:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <string>

std::string reverse(const std::string &);
bool isVowel(char);
bool isPunct(char);

int main()
{
    std::string str;
    std::cout << "Enter string (at least 2 long): " << std::flush;
    std::getline(std::cin, str);
    std::cout << '\n';
    std::cout << "Reverse of string: " << reverse(str) << '\n' <<
    "1st character is vowel: " << std::boolalpha << isVowel(str[0]) << '\n' <<
    "2nd character is punctuation: " << isPunct(str[1]) << '\n';
    
    return 0;
}

std::string reverse(const std::string &s)
{
    return std::string(s.crbegin(), s.crend());
}

bool isVowel(char c)
{
    const std::string vowels = "aAeEiIoOuU";
    return vowels.find(c) != std::string::npos;
}

bool isPunct(char c)
{
    const std::string punct = "+=%₩<>!@#~/^&*()-\'\":;,\?`_\\|{}[]$€£¥";
    return punct.find(c) != std::string::npos;
}

Enter string (at least 2 long): a^c

Reverse of string: c^a
1st character is vowel: true
2nd character is punctuation: true
Enter string (at least 2 long): abc

Reverse of string: cba
1st character is vowel: true
2dnd character is punctuation: false
Enter string (at least 2 long): c*a

Reverse of string: a*c
1st character is vowel: false
2nd character is punctuation: true
Enter string (at least 2 long): cba

Reverse of string: abc
1st character is vowel: false
2nd character is punctuation: false
Last edited on
Topic archived. No new replies allowed.