![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
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 |
|
|
|
|
|
#2 |
|
Programmer
|
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 failedWill someone be able to tell me where I went wrong and help me sort it out? Thankyou Haz |
|
|
|
|
|
#3 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
It's simple - you need a Main function. Stick public static int Main around the main program, and enclose it with curly braces.
|
|
|
|
|
|
#4 |
|
Programmer
|
Ahhh, instead of public static void Main()? THANKYOU :-D
|
|
|
|
|
|
#5 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Ah... didn't see that. In that case, move the degreesAdd function out of your Main function (but keep it in the class).
|
|
|
|
|
|
#6 |
|
Programmer
|
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 ![]() |
|
|
|
|
|
#7 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
Try taking out the last semicolon
![]() |
|
|
|
|
|
#8 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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.
|
|
|
|
|
|
#9 |
|
Professional Programmer
|
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 |
|
|
|
|
|
#10 |
|
Programmer
|
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|