Today I completed the FlipFlop program. Similiar to the previous passcode program I ask for user input to perform an action. This time the action is to flip the two present numbers. The tries allowed are unlimited. One major difference between this program and the previous was the fact that project passcode used strictly strings and project flipflop uses strings and integers. Below is the code.
namespace FlipFlop
{
class FlipFlop
{
static string strSwap = "swap";
public static void Main(string[] args)
{
string strInput;
int iInput1 = 5;
int iInput2 = 10;
int tempInput = iInput1;
do
{
Console.WriteLine("The first number is: " + iInput1);
Console.WriteLine("The second number is: " + iInput2);
Console.Write("Type swap to swap the numbers: ");
strInput = Console.ReadLine();
if (strInput == strSwap)
{
iInput1 = iInput2;
iInput2 = tempInput;
Console.WriteLine("The first number is: " + iInput1);
Console.WriteLine("The second number is: " + iInput2);
Console.WriteLine("Swap Done");
}
else
{
Console.WriteLine("No Swap");
}
}
while (strInput != strSwap);
Console.WriteLine("You are the SwapMaster");
Console.ReadLine();
}
}
}
Subscribe to:
Post Comments (Atom)
1 comment:
I like this one... I can see you really have the hang of it now.
Post a Comment