/* Program 8.2.1b from C++ Programming Lecture notes  */

/* Author: Rob Miller and William Knottenbelt
   Program last changed: 30th September 2001    */

/* This program inputs a series of characters from the keyboard, 
terminating with a '.', and then prints out the characters
backwards on the screen. */ 

#include<iostream>
using namespace std;

const int MAX_ARRAY_LENGTH = 100;

/* Function to input a series of characters from the keyboard
and then print them backwards on the screen. */
void print_backwards();

/* START OF MAIN PROGRAM */
int main()
{
	print_backwards();
	cout << endl;
	
	return 0;
}
/* END OF MAIN PROGRAM */

/* START OF DEFINITION OF FUNCTION print_backwards */
void print_backwards()
{
	char chars[MAX_ARRAY_LENGTH];
	int no_of_chars_input = 0;
	
	do {
		cout << "Enter a character ('.' to end program): ";
		cin >> chars[no_of_chars_input];
		no_of_chars_input ++;
		}
	while (chars[no_of_chars_input - 1] != '.' && no_of_chars_input < MAX_ARRAY_LENGTH);
	
	for (int count = no_of_chars_input - 2 ; count >=0 ; count--)
		cout << chars[count];
}
/* END OF FUNCTION DEFINITION */
