Ask your own question, for FREE!
Mathematics 14 Online
OpenStudy (marcelie):

any c++ programmers need help pleaseeeeeee

OpenStudy (marcelie):

its not compiling can someone please please fix it

OpenStudy (whiskyryan):

It compiles just fine for me...

OpenStudy (whiskyryan):

test run: Enter a string: hello Total count of letters(s) is 5 with 0 upper case letter(s) 5 lower case letter(s) 2 vowels(s) 3 consonants(s) The reverse string : olleh

OpenStudy (marcelie):

it didnt work into my visual studio D:

OpenStudy (whiskyryan):

are you on a mac or pc?

OpenStudy (marcelie):

pc

OpenStudy (whiskyryan):

do you have MinGW?

OpenStudy (marcelie):

no

OpenStudy (marcelie):

i see some red lines

OpenStudy (whiskyryan):

if you install it and its c++ compiler from the command line you can do: g++ part_1.cpp and it should compile just fine. I can't help you with visual studio... I am on a mac to mine compiles to a.out.... yours will compile to a.exe

OpenStudy (marcelie):

oh

OpenStudy (whiskyryan):

There is nothing wrong with those code.... maybe the compiler in your version of visual studio does not like it...

OpenStudy (marcelie):

hmmm

rvc (rvc):

try an online compiler then :)

OpenStudy (whiskyryan):

Go here: http://cpp.sh/5mxf6 ...and then click run to see your code does work.

OpenStudy (marcelie):

#include <string> #include <iostream> using namespace std; bool isPunctuation(char c); //function to check punctuation character bool isVowel(char c); //function to check character is vowel or not string reverseString(string i); //function reverses a string //Additional functions below bool isDigit(char c); //function check whether digit or not bool isWhiteSpace(char c); //function check whitespace bool isUpperCase(char c); //function checks upper case bool isLowerCase(char c); //function checks lower case int main() { //code here int letters,ucase=0,lcase=0,vowels=0,digits=0,spaces=0,others=0,pcount=0; string st; cout<<"\nEnter a string: "; getline(cin,st);//input complete string here if(st.empty()) { cout<<"\nNo string was entered"; return 1; } for(unsigned int i=0;i<st.length();i++) //repeat up to string length { //calling each function and checking true or false //and increment respective count variables if(isLowerCase(st[i])) lcase++; else if(isUpperCase(st[i])) ucase++; if(isVowel(st[i])) vowels++; else if(isPunctuation(st[i])) pcount++; else if(isWhiteSpace(st[i])) spaces++; else if(isDigit(st[i])) digits++; else if(!isLowerCase(st[i]) && !isUpperCase(st[i])) others++; } //printing of all statistics by calling functions defined letters=(lcase+ucase); //check the condition if alphabetical letters are found if(letters>0) { cout<<"\nTotal count of letters(s) is "<<letters<<" with"<<endl; cout<<"\t"<<ucase<<" upper case letter(s)"<<endl; cout<<"\t"<<lcase<<" lower case letter(s)"<<endl; cout<<"\t"<<vowels<<" vowels(s)"<<endl; cout<<"\t"<<(letters-vowels)<<" consonants(s)"<<endl; } //Check conditions for other special characters and digits and punctuations //then print each if(digits>0) cout<<"\nTotal count of digits(s) is "<<digits<<endl; if(pcount>0) cout<<"\nTotal count of punctuation mark(s) is "<<pcount<<endl; if(spaces>0) cout<<"\nTotal count of whitespace(s) is "<<spaces<<endl; if(others>0) cout<<"\nTotal count of other symbol charaters(s) is "<<others<<endl; cout<<"\nThe reverse string : "<< reverseString(st)<<endl; return 0; } //function to check punctuation character bool isPunctuation(char c) { if(c==',' || c=='.' || c=='?' || c==';' || c==':' || c=='\"' || c=='\'' || c=='{' || c=='}' || c=='[' || c==']' || c=='/' || c=='!' || c=='-' ) return true; else return false; } //function to check character is vowel or not bool isVowel(char c) { if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='A' || c=='E' || c=='I' || c=='O' || c=='U') return true; else return false; } //function reverses a string string reverseString(string i) { string rev=""; //empty string declare for(int j=i.length()-1;j>=0;j--) rev+=i[j]; return rev; } //Additional functions below //function check whether digit or not bool isDigit(char c) { if(c>='0' && c<='9') return true; else return false; } //function check whitespace bool isWhiteSpace(char c) { return c==' '; } //function checks upper case bool isUpperCase(char c) { if(c>='A' && c<='Z') return true; else return false; } //function checks lower case bool isLowerCase(char c) { if(c>='a' && c<='z') return true; else return false; }

OpenStudy (whiskyryan):

That works... did you go here: http://cpp.sh/5mxf6

OpenStudy (marcelie):

yes but the black window as the output closes automatically

rishavraj (rishavraj):

@marcelie bang ur pc against the wall

OpenStudy (marcelie):

lool yall help me out... idk why the output isnt working

rishavraj (rishavraj):

workng for me .... u can see the output

OpenStudy (marcelie):

yes it works there haha but on vs it doesnt work

OpenStudy (marcelie):

im gettin frrustrated arghh lol

OpenStudy (whiskyryan):

Do you need to turn in a compiled file or what do you need to get credit?

OpenStudy (marcelie):

well it compiles but the blakc window closes by itself :/

OpenStudy (whiskyryan):

ohhhhh i see your problem

OpenStudy (marcelie):

yes so what do i do ? D:

OpenStudy (whiskyryan):

run your program from inside the terminal... it is closing before you can see the result

OpenStudy (whiskyryan):

it is a windows thing

OpenStudy (marcelie):

yeah so what do i do

OpenStudy (whiskyryan):

ok go to the folder where your .exe file is and shift+right click in the folder

OpenStudy (whiskyryan):

then click open command prompt here

OpenStudy (whiskyryan):

then type <yourfile>.exe

OpenStudy (whiskyryan):

any luck?

OpenStudy (marcelie):

i dont see it lol

OpenStudy (whiskyryan):

ok do this instead... if you hit "win+r" do you get the run box?

OpenStudy (marcelie):

yes you mean the black box ?

OpenStudy (whiskyryan):

No. "Win+R" should open the run dialog.

OpenStudy (whiskyryan):

Then you need to type "cmd" and press enter

OpenStudy (whiskyryan):

Then navigate to your file and run it from inside the terminal.

OpenStudy (marcelie):

nvm got it .. ty all

OpenStudy (marcelie):

#include <string> #include <iostream> #include <iomanip> using namespace std; bool isPunctuation(char c); //function to check punctuation character bool isVowel(char c); //function to check character is vowel or not string reverseString(string i); //function reverses a string //Additional functions below bool isDigit(char c); //function check whether digit or not bool isWhiteSpace(char c); //function check whitespace bool isUpperCase(char c); //function checks upper case bool isLowerCase(char c); //function checks lower case int main() { //code here int letters, ucase = 0, lcase = 0, vowels = 0, digits = 0, spaces = 0, others = 0, pcount = 0; string st; cout << "Enter a string: "; getline(cin, st);//input complete string here if (st.empty()) { cout << "\nNo string was entered."; getchar(); return 1; } for (unsigned int i = 0; i<st.length(); i++) //repeat up to string length { //calling each function and checking true or false //and increment respective count variables if (isLowerCase(st[i])) lcase++; else if (isUpperCase(st[i])) ucase++; if (isVowel(st[i])) vowels++; else if (isPunctuation(st[i])) pcount++; else if (isWhiteSpace(st[i])) spaces++; else if (isDigit(st[i])) digits++; else if (!isLowerCase(st[i]) && !isUpperCase(st[i])) others++; } //printing of all statistics by calling functions defined letters = (lcase + ucase); //check the condition if alphabetical letters are found if (letters>0) { cout << "\nTotal count of letters(s) is " << letters << " with" << endl; cout << setw(11) << ucase << " upper case letter(s)" << endl; cout << setw(11) << lcase << " lower case letter(s)" << endl; cout << setw(11) << vowels << " vowels(s)" << endl; cout << setw(11) << (letters - vowels) << " consonants(s)" << endl; } //Check conditions for other special characters and digits and punctuations //then print each if (digits>0) cout << "\nTotal count of digits(s) is " << digits << endl; if (pcount>0) cout << "\nTotal count of punctuation mark(s) is " << pcount << endl; if (spaces>0) cout << "\nTotal count of whitespace(s) is " << spaces << endl; if (others>0) cout << "\nTotal count of other symbol charaters(s) is " << others << endl; cout << "\nThe reverse string : " << reverseString(st) << endl; getchar(); return 0; } //function to check punctuation character bool isPunctuation(char c) { if (c == ',' || c == '.' || c == '?' || c == ';' || c == ':' || c == '\"' || c == '\'' || c == '{' || c == '}' || c == '[' || c == ']' || c == '/' || c == '!' || c == '-' || c == '(' || c == ')') return true; else return false; } //function to check character is vowel or not bool isVowel(char c) { if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') return true; else return false; } //function reverses a string string reverseString(string i) { string rev = ""; //empty string declare for (int j = i.length() - 1; j >= 0; j--) rev += i[j]; return rev; } //Additional functions below //function check whether digit or not bool isDigit(char c) { if (c >= '0' && c <= '9') return true; else return false; } //function check whitespace bool isWhiteSpace(char c) { return c == ' '; } //function checks upper case bool isUpperCase(char c) { if (c >= 'A' && c <= 'Z') return true; else return false; } //function checks lower case bool isLowerCase(char c) { if (c >= 'a' && c <= 'z') return true; else return false; }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!