Beispiel #1
0
        static int numfirstseats(planebodyvalues p1)
        {
            string num1stseatst;
            int    num1seats;

            bool seats = false;

            do
            {
                Console.WriteLine("please enter then number of first class seats");
                num1stseatst = Console.ReadLine();

                num1seats = Convert.ToInt32(num1stseatst);

                seats = false;
                /// oh used the wrong variable
                if (num1seats >= p1.capacityifallseatsarestandardclass || num1seats < p1.minimumnumoffirstclassseats) //needs to be; if num1stseats >= number of standard class seats/2
                {
                    Console.WriteLine("error");
                    seats = false;
                }
                else
                {
                    seats = true;
                }


                // ok this is the problem. first number of seats will be checked against max seats, lets say it is below capacity
                // then it is compared to minimum seats. The else is(was) attached to the minimum seats comparison. Therefore seats could be set
                // to true even if the user selected too many seats
            } while (seats == false);

            //Convert.ToString(num1stseatst);

            return(num1seats);
        }
Beispiel #2
0
        static calculatedvalues Calculate(int num1stseats, int price1stseat, int pricestandardseat, planebodyvalues pb)
        {
            int numberofstandardclassseats;
            int flightcostperseat;
            int flightcost;
            int flightincome;
            int flightprofit;
            // do i need to declare these if they are in a stuct? No


            bool validdistancematch = false;

            bool validAirportagain = false;


            do
            {
                validAirportagain = false;

                for (int x = 0; x < code.Length; x = x + 1) //searches though overseas three letter codes
                {
                    if (code[x] == OSairportname)           //finds match
                    {
                        do
                        {
                            //following uses value of x (row) in another field (determined by which UK airport) to find correspondidng distance

                            validdistancematch = false;

                            if (ukname == "LPL")
                            {
                                distance           = Convert.ToInt32(distanceL[x]);
                                validdistancematch = true;
                            }

                            if (ukname == "BOH")
                            {
                                distance           = Convert.ToInt32(distanceB[x]);
                                validdistancematch = true;
                            }

                            // distance is changed as a global variable
                        } while (validdistancematch == false);


                        validAirportagain = true;
                    }
                }
            } while (validAirportagain == false);



            numberofstandardclassseats = pb.capacityifallseatsarestandardclass - (num1stseats * 2);
            //Each first-class seat takes up space for two standard-class seats.

            flightcostperseat = pb.runningcostperseatper100km * distance / 100;
            // need to find distance from which uk airport is to the overseas airport

            flightcost = flightcostperseat * (num1stseats + numberofstandardclassseats);

            flightincome = (num1stseats * price1stseat) + (numberofstandardclassseats * pricestandardseat);

            flightprofit = flightincome - flightcost;


            calculatedvalues point = new calculatedvalues(numberofstandardclassseats, flightcostperseat, flightcost, flightincome, flightprofit);


            return(point);
            // how/what do you return if values are stored in a struct? or do you not return anything?
            // answer =
            // you can retuen an instance of the struct, as you have you just need to add calculated values as a return type in the method signiture
        }