Kat H.

asked • 04/26/21

First Middle Last Letter. Read in a string from cin (it will not have any whitespace).

Read in a string from cin (it will not have any whitespace). Print out the first character, middle character (if string is an even length, print the second of the two middle letters), and last character without any spaces.


Samples:

Input: hello Output: hlo
Input: number Output: nbr


Hints:

  1. To get the middle/last you will need to first get the length of the string and calculate based on that
  2. The index of the last letter is not the same as the length! In "hello", the 'o' is at location 4

Code:


#include <iostream>

#include <string>

using namespace std;


//Turn off loops - you should not need them!

#define for "OhNoYouDont"

#define while "GetThatOutOfMyKitchen"



//Do not modify anything on or above the line below this

//YOUR_CODE_BELOW

int main()

{

//YOUR_CODE

}


1 Expert Answer

By:

Patrick B. answered • 04/27/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.