Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 29th, 2005, 12:38 PM   #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
Old Apr 29th, 2005, 10:37 PM   #2
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
Well I've completed it and I cmplied it, but there are some errors that I'm not exactly sure about, and everytime I try to correct them, it gets worse. Here's the code:

/* 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;
    int alt;
    double tempx;
    double x, y, z, a;
    int ac1, ac2;
    double vis;
    double dt, dg, te, dtg, ca;	
    int degreesAdd (int n1, int n2)
    {
    return (n1 + n2) % 360;
    }
     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\n")
	  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);

	    Console.WriteLine("NOTE: Make sure the units are compatible with each other");
	    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;
	}
	  case '2':
	    Console.WriteLine("Here you can calculate the ISA deviation\n");
	    Console.Write("Altitude: ");
	    alt = (int) Console.read();
	    Console.Write("Temp. at Alt.: ");
	    tempx = (double) Console.Read()

	    x = alt - 1000;
	    y = 2 * x;
	    z = 15 - x;

	    Console.WriteLine("This is the ISA temp. at that level: " + z);
	    
	    a = tempx - z;

	    Console.WriteLine("This is the ISA Deviation: " + a);
	    break;
	  
          case '3':
	    Console.WriteLine("Here you can calculate the Time to Impact of 2 aircraft\n");
	    Console.Write("Speed of Aircraft 1: ");
	    ac1 = (int) Console.Read();
	    Console.Write("Speed of Aircraft 2: ");
	    ac2 = (int) Console.Read();
	    
	    speed = ac1 + ac2;

	    Console.WriteLine("Your closing speed is: " + speed);

	    Console.WriteLine("Now the program will convert the in-flight visibility from Kilometres to Nautical Miles.");
	    
	    Console.Write("In-flight vis. (km): ");
	    vis = (double) Console.Read();
 	    
            x = ( vis * 1000 * 3.128 ) / (6076);
            Console.WriteLine("Your in-flight vis. is: " + x "nm");

	    Console.WriteLine("Now the program will calculate the time to impact in hours");
	    y = x / speed;
	    Console.WriteLine("The Time to Impact is: " + y "hours\nNow it will convert it into seconds");
	    z = y * 3600;
	    Console.WriteLine("\nYour Time to Impact is: " + z "seconds");
	    break;
	
	  case '4':
	    Console.WriteLine("Here you can calculate the Track Error, Closing Angle, and the angle at which\n to travel to get to the destiniation"); 
	    Console.Write("Distance Off Track: ");
	    dt = (double) Console.Read();
	    Console.Write("Distance Gone ");
	    dg = (double) Console.Read();
	    
	    x = (dt) / (dg);
	    y = x * 60;
	    
	    Console.WriteLine("The Track Error is: " + y "degrees");
	    
	    Console.WriteLine("Now the prgram will calculate the Closing Angle");
	    Console.Write("Distance to go: ");
	    dtg = (double) Console.Read();
	    
	    z = (dt) / (dtg);
	    
	    a = z * 60;
	    
	    Console.WriteLine("The Closing Angle is: " + a "degrees");
	    
	    Console.WriteLine("Now the program will figure out the directiong to fly to get to the destination");
	    
	    z = addDegrees (a, y);
	    
	    Console.WriteLine("The angle at which to travel to get to the destination is" + z "degrees");
	    break;
      }
	    
    }
    Console.WriteLine();
	}
}

And here's the output:

AviProgram.cs(20,32): error CS1513: } expected
AviProgram.cs(25,6): error CS1519: Invalid token 'for' in class, struct, or interface member declaration
AviProgram.cs(28,19): error CS1519: Invalid token '(' in class, struct, or interface member declaration
AviProgram.cs(29,19): error CS1519: Invalid token '(' in class, struct, or interface member declaration
AviProgram.cs(30,19): error CS1519: Invalid token '(' in class, struct, or interface member declaration
AviProgram.cs(31,22): error CS1519: Invalid token '(' in class, struct, or interface member declaration
AviProgram.cs(32,19): error CS1519: Invalid token '(' in class, struct, or interface member declaration
AviProgram.cs(33,15): error CS1519: Invalid token '(' in class, struct, or interface member declaration
AviProgram.cs(35,11): error CS1519: Invalid token '=' in class, struct, or interface member declaration
AviProgram.cs(35,18): error CS1519: Invalid token ')' in class, struct, or interface member declaration
AviProgram.cs(35,32): error CS1519: Invalid token '(' in class, struct, or interface member declaration
AviProgram.cs(36,11): error CS0116: A namespace does not directly contain members such as fields or methods
AviProgram.cs(37,7): error CS1022: Type or namespace definition, or end-of-file expected

---------------------- Done ----------------------

Build: 0 succeeded, 0 failed

Will someone be able to tell me where I went wrong and help me sort it out? Thankyou

Haz
Haz is offline   Reply With Quote
Old Apr 30th, 2005, 8:26 AM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
It's simple - you need a Main function. Stick public static int Main around the main program, and enclose it with curly braces.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 30th, 2005, 11:07 AM   #4
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
Ahhh, instead of public static void Main()? THANKYOU :-D
Haz is offline   Reply With Quote
Old May 1st, 2005, 5:49 AM   #5
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Ah... didn't see that. In that case, move the degreesAdd function out of your Main function (but keep it in the class).
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 1st, 2005, 9:44 PM   #6
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
Yep, kind of worked, just ONE more error to sort out :-(.

AviProgram.cs(183,1): error CS1022: Type or namespace definition, or end-of-file expected

/* Aviation program for Pilots

   Created by Harry Wheildon  */

using System;

class Avi {
	int degreesAdd (int n1, int n2)
	{
		return (n1 + n2) % 360;
	}
	public static int Main() {
		char choice;
		char std;
		double speed;
		double distance;
		double time;
		int alt;
		double tempx;
		double x, y, z, a;
		int ac1, ac2;
		double vis;
		double dt, dg, te, dtg, ca;
		
		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':
					do {
						Console.WriteLine("Here you can calculate the Speed, Distance or Time\n");
						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: ");
						do {
							std = (char) Console.Read();
						} while(choice == '\n' | choice == '\r');
					} while( choice < '1' | choice > '3');
					
					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);
							
							Console.WriteLine("NOTE: Make sure the units are compatible with each other");
							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;
					}
			}
			
		case '2':
			Console.WriteLine("Here you can calculate the ISA deviation\n");
			Console.Write("Altitude: ");
			alt = (int) Console.read();
			Console.Write("Temp. at Alt.: ");
			tempx = (double) Console.Read()
				
				x = alt - 1000;
			y = 2 * x;
			z = 15 - x;
			
			Console.WriteLine("This is the ISA temp. at that level: " + z);
			
			a = tempx - z;
			
			Console.WriteLine("This is the ISA Deviation: " + a);
			break;
			
		case '3':
			Console.WriteLine("Here you can calculate the Time to Impact of 2 aircraft\n");
			Console.Write("Speed of Aircraft 1: ");
			ac1 = (int) Console.Read();
			Console.Write("Speed of Aircraft 2: ");
			ac2 = (int) Console.Read();
			
			speed = ac1 + ac2;
			
			Console.WriteLine("Your closing speed is: " + speed);
			
			Console.WriteLine("Now the program will convert the in-flight visibility from Kilometres to Nautical Miles.");
			
			Console.Write("In-flight vis. (km): ");
			vis = (double) Console.Read();
			
			x = ( vis * 1000 * 3.128 ) / (6076);
			Console.WriteLine("Your in-flight vis. is: " + x + "nm");
			
			Console.WriteLine("Now the program will calculate the time to impact in hours");
			y = x / speed;
			Console.WriteLine("The Time to Impact is: " + y + "hours\nNow it will convert it into seconds");
			z = y * 3600;
			Console.WriteLine("\nYour Time to Impact is: " + z + "seconds");
			break;
			
		case '4':
			Console.WriteLine("Here you can calculate the Track Error, Closing Angle, and the angle at which\n to travel to get to the destiniation");
			Console.Write("Distance Off Track: ");
			dt = (double) Console.Read();
			Console.Write("Distance Gone ");
			dg = (double) Console.Read();
			
			x = (dt) / (dg);
			y = x * 60;
			
			Console.WriteLine("The Track Error is: " + y + "degrees");
			
			Console.WriteLine("Now the program will calculate the Closing Angle");
			Console.Write("Distance to go: ");
			dtg = (double) Console.Read();
			
			z = (dt) / (dtg);
			
			a = z * 60;
			
			Console.WriteLine("The Closing Angle is: " + a + "degrees");
			
			Console.WriteLine("Now the program will figure out the direction to fly to get to the destination");
			
			z = addDegrees (a, y);
			
			Console.WriteLine("The angle at which to travel to get to the destination is" + z + "degrees");
			break;
		}
		Console.WriteLine();
	}
  }
}


That's the code completed so far.

Thanks for all the help you guys have given me
Haz is offline   Reply With Quote
Old May 2nd, 2005, 12:30 AM   #7
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
Try taking out the last semicolon
Dameon is offline   Reply With Quote
Old May 2nd, 2005, 7:00 AM   #8
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
There's a } where it shouldn't be, or one missing. I'm too lazy to find it, however - just scour your code until you find it.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 2nd, 2005, 9:09 AM   #9
peace_of_mind
Professional Programmer
 
peace_of_mind's Avatar
 
Join Date: Sep 2004
Location: Hell if I know most of the time
Posts: 439
Rep Power: 5 peace_of_mind is on a distinguished road
Send a message via MSN to peace_of_mind Send a message via Yahoo to peace_of_mind
I copy/pasted into dev, just to check for matching braces. It appears that last brace is not needed.
__________________
Amateurs built the ark
Professionals built the Titanic

peace_of_mind is offline   Reply With Quote
Old May 2nd, 2005, 10:27 AM   #10
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
Hmmm I tried that but it turned out with dodgy errors. (Besides, that's the brace that connects to Class Avi { isn't it? I also ran through the program and it seems that all brace are fine.

I put the brace back in and it now only has 2 errors:

Avi Program.cs(43,4): error CS0163 : Control cannot fall through from one case level ('case 49:') to another
Avi Program.cs(176,8): error CS0103: The name 'addDegrees' does not exist in the class or namespace 'Avi'

EDIT: I've managed to sort out the first error, it turned out I needed to break the entire switch(std) as it was a nested switch.

Now all I need to do is solve the 2nd error!

Help please!

Last edited by Haz; May 2nd, 2005 at 9:29 PM.
Haz is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:00 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC