C++ program functions

#include <iostream>
#include <string>
using namespace std;

int GetNumOfNonWSCharacters();
FindText();
ReplaceExclamation();
ShortenSpace();
GetNumOfWords();


int GetNumOfWords(char * numWords){

int i=0;
int words=0;
while(numWords[i] != '\0')
{
if(numWords[i] == '\t')
{
words++;
}
i++;
}



return words;

}

int GetNumOfNonWSCharacters(string numWhite)
{
int count = 0;
for(unsigned int i = 0; i < numWhite.size(); ++i) {
if (!isspace(numWhite[i]))
++count;
}
cout << "Number of non-whitespace characters: " << count << endl;
return count;
}

void PrintMenu() {

char userInput;

cout << "MENU" << endl;
cout << "c - Number of non-whitespace characters" << endl;
cout << "w - Number of words" << endl;
cout << "f - Find text"<< endl;
cout << "r - Replace all !'s" << endl;
cout << "s - Shorten spaces" << endl;
cout << "q - Quit" << endl;
cout << endl;
cout << "Choose an option: "<< endl;
cin >> userInput;


switch (userInput) {
case 'c':
GetNumOfNonWSCharacters();
break;

case 'w':
GetNumOfWords();
break;

case 'f':
FindText();
break;

case 'r':
ReplaceExclamation();
break;

case 's':
ShortenSpace();
break;

case 'q':
break;

default: cout << userInput << "Choose an option: " ;

}
}

int main() {
string userInput;
string menu;
string numChar;
string numWhite;
string option;


cout << "Enter a sample text: " << endl;
getline(cin, userInput);
cout << "You entered: " << userInput << endl;
cout << endl;

PrintMenu();

return 0;
}
Last edited on
What is your question?
how can i make the menu work


i have this
#include <iostream>
#include <string>
using namespace std;

int GetNumOfNonWSCharacters(string);
int FindText(string, string);
int ReplaceExclamation(string);
int ShortenSpace(string);
int GetNumOfWords(string);


///menu fucntion

void PrintMenu() {


cout << "MENU" << endl;
cout << "c - Number of non-whitespace characters" << endl;
cout << "w - Number of words" << endl;
cout << "f - Find text"<< endl;
cout << "r - Replace all !'s" << endl;
cout << "s - Shorten spaces" << endl;
cout << "q - Quit" << endl;
cout << endl;
cout << "Choose an option: " << endl;

}


int main() {


const int GetNumOfNonWSCharacters = 'c',
FindText = 'f',
ReplaceExclamation = 'r',
ShortenSpace = 's',
GetNumOfWords = 'w';
char option;
string userInput;

cout << "Enter a sample text: " << endl;
getline(cin, userInput);
cout << "You entered: " << userInput << endl;
cout << endl;

PrintMenu();

do {


cin >> option;

if (option == 'q'){
break;
}

switch (option) {
case GetNumOfNonWSCharacters:
int GetNumOfNonWSCharacters();
break;

case GetNumOfWords:
int GetNumOfWords();
break;

case FindText:
int FindText();
break;

case ReplaceExclamation:
int ReplaceExclamation();
break;

case ShortenSpace:
int ShortenSpace();
break;

case 'q':

break;

}
}while (option != 'q');

return 0;
}

/////////num of words///////////
int GetNumOfWords(char * numWords){

int i=0;
int words=0;
while(numWords[i] != '\0')
{
if(numWords[i] == '\t')
{
words++;
}
i++;
}

return words;

}
/////////////num of characters///////
int GetNumOfNonWSCharacters(string numWhite)
{
int count = 0;
for(unsigned int i = 0; i < numWhite.size(); ++i) {
if (!isspace(numWhite[i]))
++count;
}
cout << "Number of non-whitespace characters: " << count << endl;
return count;
}
Topic archived. No new replies allowed.