Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Language: C++ So I'm trying to make a program right now. I try to use a c-string to get the name and output the

Programming Language: C++

So I'm trying to make a program right now. I try to use a c-string to get the name and output the user input using menu #2 Also, I want to send an error message and ask the user to input the name again when user input blank (This is menu #1, inputName).

The real problem is, I know how to send the error message when I have an empty string, but not when I have an empty c- string.

This is my program.

#include "stdafx.h" #include  #include  #include  using namespace std; //Signature of the methods which are //implemented below to main method void inputName(char []); void lowerCaseLetters(char[]); void displayName(char[]); void countWords(char[]); void reverseName(char[]); void mostCharacter(char[]); void display_menu() { //Display menu for user selection cout << "The Name game: " << endl; cout << "1. Input Full Name " << endl; cout << "2. Display Name " << endl; cout << "3. Change my name to all lower case " << endl; cout << "4. Count and display the number of words in name" << endl; cout << "5. Reverse the name " << endl; cout << "6. Display the most frequent character " << endl; cout << "7. Exit Menu " << endl; } //Main method which executes the program int main() { int pick = 0; const int SIZE = 40; char name[SIZE]; while (true) { display_menu(); cin >> pick; cin.ignore(); switch (pick) { case 1: cout << "1. Input Name: "; inputName(name); break; case 2: cout << "2. Display Name: "; displayName(name); break; case 3: cout << "3. Change to Lower: "; lowerCaseLetters(name); break; case 4: cout << "4. Count: "; countWords(name); break; case 5: cout << "5. Reverse Name: "; reverseName(name); break; case 6: cout << "6. Most Letters: "; mostCharacter(name); break; case 7: cout << "Exit the Program. Bye Bye!" << endl; return 0; break; default: cout << "Invalid choice Please Choose menu Option (1-7)" << endl; break; } } } void inputName(char userName[]) { const int SIZE = 40; cin.getline(userName, SIZE); } //Method to convert the user input to lower case void lowerCaseLetters(char userName[]) { int sizeOfArray = strlen(userName); for (int i = 0; i <= sizeOfArray; i++) { userName[i] = tolower(userName[i]); } cout << "Your name has been converted to lower case." << endl; } //Method to display the user input in console void displayName(char userName[]) { cout << userName << endl; } //Method to count the total words in user input void countWords(char userName[]) { int count = 0; int wordCount = 0; int userNameLength = strlen(userName); while (count < userNameLength) { while (userName[count] != ' ' && userName[count] != '\0') count++; wordCount += 1; while (userName[count] == ' ') { count++; } } cout << "There are " << wordCount << " words in your name." << endl; } //Method to reverse the user input letters void reverseName(char userName[]) { char temp; int i = 0; int j = strlen(userName) - 1; while (i 

I want my program to print out the error message if I put blank input after I choose number 1 for menu choice.

Please, don't change the whole program, like change to printf or using define.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

18. Show that when r = 2 the multinomial reduces to the binomial.

Answered: 1 week ago

Question

Who was your favorite teacher in school and why?

Answered: 1 week ago