Message

Based on the algorithm , was made program "Message" for multiple message print on the monitor. At the bottom of the page ia attached Message.rar archive with a complete program solution.

If you analyze the code you shall notice that in one place program deviates from algorithm. When programs made for professional use it is not recommended.

This is the part that refers to the way in which is resolved counting of how many times the message printed.

In the algorithm it is realized through BrojačPonavljanja, variable whose value is reduced from a maximum of five to zero.

In this program it is variable Counter type int whose value increases from zero to a maximum of five.

Caution!

It does not matter the name of the variable, important is the way in which variable changes its value in the program in the WHILE loop.

You should take care not to make a mistake in the question posed by the requirement for completion of the loop in this program to the

while ( Counter < MaxRepeatCounter )

MaxRepeatCounter contains the value of five set in the variable declaration.

If the Counter grew from one to five, there would be only four print messages.

Try to change your code and write your own program exactly as it is written in the algorithm.

Also, if the question (condition) is to be like this

while ( Counter ! = MaxRepeatCounter ) ( "! =" means "not equal")

then the variable Counter should have an initial value of one.

The value of the variable Counter is incremented by one before printing a message on the screen!

This is important because it starts from zero and the first message had this look:

Message no. 0, and this should not happen.

The program is limited the length of the entered message to forty letters (characters), it is checked,

after entering the message, review the program.

Program code is different from the algorithm in a variety of steps to define

graphical user interface (GUI - graphic user interface), or whatever the user sees

on a monitor while using a program, such as in this case, a line of code to print titles, line

underlining or separation of the text which uses the symbol "-", etc.

Try to shape Your own GUI that suits to You and to the program to look more beautiful and functional.

/*

* Created by SharpDevelop.

* User: Perić Željko

* Date: 28.01.2012

* Time: 14:09

*

* Simple console application for writing message that user has entered by keyboard.

* Message can have only 40 caracters

*/

using System;

namespace Message

{

class Program

{

public static void Main(string[] args)

{

//

// Declaration of variables

//

const int MaxMessageLenght = 40;

const int MaxRepeatCounter = 5;

int Counter = 0;

string Message = "Hello , shell we play a game";

//

// Set console atributes , clear console , write title

//

Console.SetWindowSize(80,25);

Console.ForegroundColor = ConsoleColor.Green;

Console.Title = "Message - by Perić Željko (periczeljkosmederevo@yahoo.com)";

Console.Clear();

Console.WriteLine(" Program Message");

Console.WriteLine("-------------------------------------------------------------------------------");

Console.WriteLine();

//

// Get message from console and check its lenght.

// If lenght is grater than 40 caracters write error message, play beep signal

// and get message again.

//

Console.WriteLine(" Hello, please enter your message ( max 40 caracters ) :");

Console.WriteLine("-------------------------------------------------------------------------------");

Message = Console.ReadLine();

Console.WriteLine("-------------------------------------------------------------------------------");

while (Message.Length > MaxMessageLenght)

{

Message = " ";

Console.WriteLine(" Error , you have entered message longer than 40 caracters !");

Console.Beep();

Console.WriteLine("-------------------------------------------------------------------------------");

Console.WriteLine(" Hello, please enter your message ( max 40 caracters ) :");

Console.WriteLine("-------------------------------------------------------------------------------");

Message = Console.ReadLine();

Console.WriteLine("-------------------------------------------------------------------------------");

}

//

// Write message 5 times

//

Counter = 0;

while ( Counter < MaxRepeatCounter )

{

Counter = Counter + 1;

Console.WriteLine("Repeat no. " + Counter.ToString() + " " +Message.ToString());

}

Console.WriteLine("-------------------------------------------------------------------------------");

Console.Write("Press any key to continue . . . ");

Console.ReadKey(true);

}

}

}

All the best,

Author