Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

QUESTION: Write a C++ program that prompts the user for three words. Ask the user to prompt 3 numbers, that should be less than the

QUESTION: Write a C++ program that prompts the user for three words. Ask the user to prompt 3 numbers, that should be less than the length of each word to indicate length of substring in each word. Create a new word, which merge the substring of 3 words. If the entered number is even, the substring starts from the first letter; if it is odd, the substring starts from the second letter

Everything works fine until the new generated word. Nothing is displayed. please help!

#include // For cin, cout, endl

#include // For string, length(), substr()

using namespace std;

int main()

{

// Declaring variables

string word1; // First word

string word2;

string word3;

string newWord; // New generated word

int num1;

int num2;

int num3;

// Prompt user for the 3 words

cout << "Please enter 3 words : ";

cin >> word1 >> word2 >> word3;

cout << endl;

// Prompt user for first number

cout << "Enter the 1st number less than "<<(word1.length())<< ": ";

getline(cin, word1);

cin >> num1;

cout << endl;

// Prompt user for second number

cout << "Enter the 2nd number less than "<<(word2.length())<<": ";

getline(cin,word2);

cin >> num2;

cout << endl;

// Prompt user for third number

cout << "Enter the 3rd number less than "<<(word3.length())<<": ";

getline(cin,word3);

cin >> num3;

cout << endl;

// Generate the new word

if (num1%2==0 && num2%2==0 && num3%2==0){ // If number entered is even

string word_1 = word1.substr(0, num1); // Substring starts from first letter

string word_2 = word2.substr(0, num2);

string word_3 = word3.substr(0, num3);

cout << "The new word is: "<

}

if (num1%2!=0 && num2%2!=0 && num3%2!=0){ // If number entered is odd

string word_1_odd = word1.substr(1, num1); // Substring starts from second letter

string word_2_odd = word2.substr(1, num2);

string word_3_odd = word3.substr(1, num3);

cout << "The new word is: "<

}

return (0);

}

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

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions

Question

Discuss the techniques of job analysis.

Answered: 1 week ago

Question

How do we do subnetting in IPv6?Explain with a suitable example.

Answered: 1 week ago

Question

Explain the guideline for job description.

Answered: 1 week ago

Question

What is job description ? State the uses of job description.

Answered: 1 week ago

Question

What are the objectives of job evaluation ?

Answered: 1 week ago