199k views
1 vote
Write a program that asks the user for three names, then prints the names in reverse order.

Please enter three names:
Zoey
Zeb
Zena
Zena
Zeb
Zoey

User Fydo
by
4.2k points

1 Answer

5 votes

Answer:

The program written in C++ is as follows'

#include<iostream>

using namespace std;

int main()

{

string names[3];

cout<<"Please enter three names: "<<endl;

for (int i = 0; i< 3;i++)

{

cin>>names[i];

}

for (int i = 2; i>= 0;i--)

{

cout<<names[i]<<endl;

}

return 0;

}

Step-by-step explanation:

This line declares an array for 3 elements

string names[3];

This line prompts user for three names

cout<<"Please enter three names: "<<endl;

This following iteration lets user input the three names

for (int i = 0; i< 3;i++) { cin>>names[i]; }

The following iteration prints the three names in reverse order

for (int i = 2; i>= 0;i--) { cout<<names[i]<<endl; }

User Thomas Rushton
by
4.3k points