(9.10 Code Practice: Question 1)

Instructions
Write code that takes in two words from user input. Then, the program should swap the two variables that hold the inputs and print the words in backward order.

Sample Run
Enter a word: apple
Enter a word: zebra
zebra
apple

Respuesta :

Answer:

#include <iostream>  

#include <string>

using namespace std;  

int main() {

 string wOne, wTwo, temp;

 cout << "Enter a word:";

 cin >> wOne;

 cout << "Enter a word:";

 cin >> wTwo;

 

 temp = wOne;

 wOne = wTwo;

 wTwo = temp;

 cout << wOne << endl;

 cout << wTwo << endl;

 

}