View Single Post
Old Apr 29th, 2005, 11:38 AM   #1
Haz
Programmer
 
Haz's Avatar
 
Join Date: Feb 2005
Location: England
Posts: 37
Rep Power: 0 Haz is on a distinguished road
Send a message via ICQ to Haz Send a message via AIM to Haz Send a message via MSN to Haz Send a message via Yahoo to Haz
C# Pilot Program

Hey guys, I've posted this somewhere on the site before but I thought I'd post it here. I'm making a little program of my own for pilots (mainly for getting my practice on the code) so here it goes:

/* Aviation program for Pilots

   Created by Harry Wheildon  */

using System;

class Avi {
  public static void Main() {

    char choice;
    char std;
    double speed;
    double distance;
    double time;
    // Insert future variables here

     for(;;) {
     	 do {              

	Console.WriteLine("Choose one from the list:\n");	
	Console.WriteLine("1.  Speed; Distance; Time");
	Console.WriteLine("2.  ISA Deviation");
        Console.WriteLine("3.  Time to Impact");
	Console.WriteLine("4.  Track Error; Closing Angle\n");
	Console.Write("Choose one (press Q to quit): ");
	do {
	  choice = (char) Console.Read();
        } while(choice == '\n' | choice == '\r');
      } while( choice < '1' | choice > '4' & choice != 'q');

      if(choice == 'q') break;

      Console.WriteLine("\n");

      switch(choice) {
	case '1':
	  Console.WriteLine("Here you can calculate the Speed, Distance or Time")
	  Console.WriteLine("Choose which one you want to calculate:")
	  Console.WriteLine("1.  Speed")
 	  Console.WriteLine("2.  Distance")
	  Console.WriteLine("3.  Time\n")
	  Console.Write("Choose one (press B to go back): ");
	  do {
	   std = (char) Console.Read();
	  } while(choice == '\n' | choice == '\r');
	} while( choice < '1' | choice > '3' & choice != 'b');

	if(choice == 'b') break;

	Console.WriteLine("\n");
	
	switch(std) {
  	  case '1':
	    Console.Write("Distance: ");
	    distance = (double) Console.Read();
	    Console.Write("Time: ");
	    time = (double) Console.Read();

	    speed = distance / time;

	    Console.WriteLine("Your Distance was: " + distance);
	    Console.WriteLine("Your Time was: " + time);

            Console.WriteLine("Thus your Speed is " + speed);
	    break;

	  case '2':
	    Console.Write("Speed: ");
	    speed = (double) Console.Read();
	    Console.Write("Time: ");
	    time = (double) Console.Read();

	    distance = speed * time;

	    Console.WriteLine("Your Speed was: " + speed);
	    Console.WriteLine("Your Time was: " + time);
	    
	    Console.WriteLine("Thus your Distance is: " + distance);
	    break;

	  case '3':
	    Console.Write("Speed: ");
	    speed = (double) Console.Read();
	    Console.Write("Distance: ");
	    distance = (double) Console.Read();

	    time = distance / speed;

	    Console.WriteLine("Your Speed was: " + speed);
	    Console.WriteLine("Your Distance was: " + distance);
	    
	    Console.WriteLine("Thus your Time is: " + time);
	    break;

There it is, and I was just wondering, now that I've done a switch inside a switch, will it need to be inside a block (The second piece of code for the Speed, Distance and Time)? If it doesn't, then what will I do with that very end break to end the case '1' of the whole SDT, and the case '3' of the Speed calculation? Will I need to put:

  case '3':
	    Console.Write("Speed: ");
	    speed = (double) Console.Read();
	    Console.Write("Distance: ");
	    distance = (double) Console.Read();

	    time = distance / speed;

	    Console.WriteLine("Your Speed was: " + speed);
	    Console.WriteLine("Your Distance was: " + distance);
	    
	    Console.WriteLine("Thus your Time is: " + time);
	    break;
            break;

Or will I of course use a block around the switch inside the switch?

Thanks for reading,

Haz
Haz is offline   Reply With Quote