I have the below code which in theory works aside form the fact it complains about my converting the string variable to a char variable, which I only did cause it bitched even worse about just run the string variable through the "if" loop. Please somebody help me.
Code:#include <iostream> #include <fstream> #include <string> #include <cstdio> #include <cstdlib> using namespace std; #ifdef _WIN32 const char CLRSCR[] = {"cls"}; const char PAUSE[] = {"pause"}; #else const char CLRSCR[] = {"clear"}; const char PAUSE[] = {"sleep(20)"}; #endif int main(void) { string name; cout << "Welcome\n" << endl; cout << "This program will allow you to enter any size paragraph and will return the number of characters in that paragraph.\n You will enter a paragraph and when finished, press enter.\n" << endl; system(PAUSE); system(CLRSCR); string name; //string will hold the input from the user cout << "Enter your name and press enter when done: " << endl; cout << "\n"; cin.get(name); cout << endl; char next; int characters = 0; int digits = 0; int upper = 0; int lower = 0; int space = 0; int eospm = 0; int others = 0; name=next; //calculate total numbers of characters including space if(isalnum(next)) characters++; //calculate total numbers of digits if(isdigit(next)) ++digits; //calculate total numbers of uppercase if(isupper(next)) ++upper; //calculate total numbers of lowercase if(islower(next)) ++lower; //calculate total numbers of space if(isspace(next)) ++space; //calculate total numbers of punctuation if(ispunct(next)){ ++others; switch(next){ case '?': case '.': case '!': ++eospm; break; default: break; } } // Print out what is counted. cout << "Total Number of Characters: " << space+digits+upper+lower+others << endl; cout << "" << endl; cout << "Total Number of Uppercase: " << upper << endl; cout << "Total Number of Lowercase: " << lower << endl; cout << "Total Number of Digits: " << digits << endl; cout << "Total Number of Space: " << space << endl; cout << "Total Number of End-of-Sentence Punctuation Marks: " << eospm << endl; cout << "Total Number of Other Characters: " << others << endl; cout << "" << endl; system(PAUSE); return 0; }
Results 1 to 2 of 2
Thread: Code Help
- 24 Mar. 2010 03:04pm #1
Global Moderator Literally Hitler
Morbidly Obese
Bird Jesus
- Age
- 35
- Join Date
- Nov. 2009
- Location
- The Land Of Ooo
- Posts
- 8,569
- Reputation
- 711
- LCash
- 20.00
Code Help
- 24 Mar. 2010 03:44pm #2
U want halp.
But wut u nedz, iz supar powrez.Logical gamers? More like get high and start pushing buttons god damn.