Write a code for the following requirement.
The program must prompt for a name, and then tell the user how many letters are in the name, what the first letter of the name is, and what the last letter of the name is. It should then end with a goodbye message. A sample transcript of what your program should do is below - user input is in bold:
Enter your name: Jeremy
Hello Jeremy!
Your name is 6 letters long.
Your name starts with a J.
Your name ends with a y.
Goodbye!

Respuesta :

Answer:

// This program is written in C++

// Comments are used for explanatory purposes

// Program starts here

#include<iostream>

using namespace std;

int main()

{

// Declare Variable name

string name;

// Prompt user for input

cout<<"Enter your name: ";

cin>>name;

// Print name

cout<<"Hello, "<<name<<"!\n";

// Print length of name

cout<<"Your name is "<<name.length()<<" letters long\n";

// Print first character

cout<<"Your name starts with a "<<name.at(0)<<"\n";

// Print last character

cout<<"Your name end with a "<<name.at(name.length()-1)<<"\n";

cout<<"Goodbye!";

return 0;

}

Answer:

jeremy

Explanation: