Пример #1
0
        static void Main() //testing routine
        {
            string s = UIF.PromptLine("Enter a line: ");

            Console.WriteLine("Reversed:");
            PrintReversed("\n" + s);
        }
Пример #2
0
        /// Prompt the user with a question; Return true of false.
        /// Allow certain starting characters for true (t, y) and
        /// others for false (f, n), and repeat until the response
        /// is in one of these groups.
        static Boolean Agree(string question)
        {
            int done = 0;

            question = UIF.PromptLine("Do you understand? Use 'y' or 'n'." + "\n");

            while (done == 0)
            {
                string res = question.ToLower();

                if (res.Length == 0)
                {
                    res = UIF.PromptLine("Please enter a response. Use 'y' or 'n'." + "\n");
                    return(false);
                }
                else if ((res != "y") || (res != "n"))
                {
                    res = UIF.PromptLine("Try again, we didn't understand your request. Use 'y' or 'n'." + "\n");
                }

                if (res == "y")
                {
                    done = 1;
                    return(true);
                }
                else if (res == "n")
                {
                    done = 1;
                    return(false);
                }
            }
            return(true);
        }
Пример #3
0
        public static void LastFirst1()
        {
            string input3 = UIF.PromptLine("Please enter a name:");
            int    space  = input3.IndexOf(" ");
            string first  = input3.Substring(0, space);
            string last   = input3.Substring(space);

            Console.WriteLine("{0}, {1}", last, first);
        }
Пример #4
0
        public static void Main(string[] args)
        {
            string input = UIF.PromptLine("Please enter a string:");

            ShowLength(input);
            SentenceType();
            LastFirst1();
            LastFirst2();
        }
Пример #5
0
        /// Return a double entered by the user.  Catch input
        /// errors, and keep promping the user until a legal
        /// decimal entry is made.  Return the corresponding double.  .
        static double PromptDouble(string prompt)
        {          //FIX so loops until legal
            double ans = 0.00;

            while (IsDecimalString(prompt) != true)
            {
                string nStr = UIF.PromptLine(prompt).Trim();
                ans = double.Parse(nStr);
            }
            return(ans);
        }
Пример #6
0
        /// Return an int entered by the user.  Catch input
        /// errors, and keep promping the user until a
        /// legal entry is made.  Return the corresponding int.
        static int PromptInt(string prompt)
        {         //FIX so loops until legal
            int ans = 0;

            while (IsIntString(prompt) != true)
            {
                string nStr = UIF.PromptLine(prompt).Trim();
                ans = int.Parse(nStr);
            }
            return(ans);
        }
Пример #7
0
        /// Return a whole number.  Catch input
        /// errors, and keep prompting the user until
        /// a legal entry is made, and return
        /// the corresponding int.  Trim extra whitespace.
        static int PromptWhole(string prompt)
        {
            string userinput = UIF.PromptLine(prompt);
            bool   digitTest = IsDigits(userinput);

            while (digitTest == false)
            {
                userinput = UIF.PromptLine("Enter an integer: ");
                digitTest = IsDigits(userinput);
            }
            return(int.Parse(userinput));
        }
Пример #8
0
        static void Main() //testing routine
        {
            string s = UIF.PromptLine("Enter a line: ");

            if (IsDigits(s))
            {
                Console.WriteLine("Only digits in {0}", s);
            }
            else
            {
                Console.WriteLine("Not only digits in {0}", s);
            }
        }
Пример #9
0
        static void Main() //testing routine
        {
            string maybeNum = UIF.PromptLine("Enter a number, maybe: ");

            Console.WriteLine("{0}: Is it a legal int? {1}.  A double? {2}",
                              maybeNum, IsIntString(maybeNum), IsDecimalString(maybeNum));
            int n = PromptInt("Enter a score: ");

            Console.WriteLine("Your score is {0}.", n);
            double x = PromptDouble("Enter a decimal number: ");

            Console.WriteLine("Your number is {0}.", x);
        }
Пример #10
0
        public static void Main()
        {
            string x = UIF.PromptLine("Enter the whole word: ");
            string y = UIF.PromptLine("Enter the part you need: ");

            if (CountRep(x, y) == 1)
            {
                Console.Write("The part occurs {0} time.", CountRep(x, y));
            }
            else
            {
                Console.Write("The part occurs {0} times.", CountRep(x, y));
            }
        }
Пример #11
0
        public static void Main(string[] args)
        {
            string       course = UIF.PromptLine("Enter course abbreviation: ");
            StreamReader reader = FIO.OpenReader("categories_" + course + ".txt");

            string category = reader.ReadLine();

            string[] categories = category.Split(',');
            for (int i = 0; i < categories.Length; i++)
            {
                categories[i] = categories[i].Trim();
            }

            string weights = reader.ReadLine().Trim();

            string[] weightAmount  = weights.Split(',');
            double[] WeightNumbers = new double[weightAmount.Length];
            double[] weightTotal   = { 0 };
            for (int i = 0; i < WeightNumbers.Length; i++)
            {
                WeightNumbers[i] = double.Parse(weightAmount[i]);
            }
            for (int i = 0; i < WeightNumbers.Length; i++)
            {
                weightTotal[0] += WeightNumbers[i];
            }

            string items = reader.ReadLine().Trim();

            string[] itemAmount  = items.Split(',');
            double[] itemNumbers = new double[itemAmount.Length];
            for (int i = 0; i < itemNumbers.Length; i++)
            {
                itemNumbers[i] = int.Parse(itemAmount[i]);
            }

            StreamWriter writer  = new StreamWriter("report_" + course + ".txt");
            StreamReader reader2 = FIO.OpenReader("students_" + course + ".txt");

            while (!reader2.EndOfStream)
            {
                string   StudentData = reader2.ReadLine().Trim();
                string[] StudentInfo = StudentData.Split(',');
                double   percentage  = Final(FinalCategory(CategoryAverage(RunningTotal(StudentInfo[0], course, categories), itemNumbers), WeightNumbers, weightTotal));
                string   letter      = LetterGrade(Final(FinalCategory(CategoryAverage(RunningTotal(StudentInfo[0], course, categories), itemNumbers), WeightNumbers, weightTotal)));
                writer.WriteLine("{0},{1} {2:F1} {3}", StudentInfo[1], StudentInfo[2], percentage, letter);
            }
            writer.Close();
            reader.Close();
        }
Пример #12
0
        public static void LastFirst2()
        {
            string input4 = UIF.PromptLine("Please enter a name:");
            int    space  = input4.IndexOf(" ");

            if (space == -1)
            {
                Console.WriteLine(input4);
            }
            else
            {
                string first = input4.Substring(0, space);
                string last  = input4.Substring(space);
                Console.WriteLine("{0}, {1}", last, first);
            }
        }
Пример #13
0
        /// Return a whole number.  Catch input
        /// errors, and keep prompting the user until
        /// a legal entry is made, and return
        /// the corresponding int.  Trim extra whitespace.
        static int PromptWhole(string prompt)
        {
            int done = 0;
            int x    = 0;

            while (done == 0)
            {
                prompt = UIF.PromptLine("Enter a whole number: ");

                string prmt = prompt.Trim();                 //this removes the blank space at the start and ends

                //below is a while loop that replaces spaces inbetween ints with no spaces
                int i = 0;
                while (i < prompt.Length)
                {
                    if (prompt[i].Equals(" "))
                    {
                        prompt.Replace(" ", "");
                    }
                    i++;
                }

                if (IsDigits(prmt) == true)
                {
                    x = int.Parse(prompt);

                    if (x >= 0)
                    {
                        done = 1;
                        return(x);
                    }
                    else
                    {
                        Console.Write("There has been an error (1)" + "\n");
                        x    = PromptWhole("Enter a whole number: ");
                        done = 0;
                    }
                }
                else
                {
                    Console.Write("There has been an error (2)" + "\n");
                    x    = PromptWhole("Enter a whole number: ");
                    done = 0;
                }
            }
            return(x);
        }
Пример #14
0
        public static void Main()
        {
            List <string> c     = Comments(comments);
            int           money = UIF.PromptInt(c[4]);

            if (money >= 50)
            {
                Console.WriteLine(c[5]);
            }
            else
            {
                Console.WriteLine(c[6]);
            }
            Player p = new Player(money);
            string z = "y";

            while (z == "y")
            {
                string betting = UIF.PromptLine("Would you like to bet?");
                p.betting = betting;
                if (betting == "betting")
                {
                    int bet = UIF.PromptLine(c[7]);
                    p.bet = bet;
                }
                string outcome = Play();
                if (outcome == c[1])
                {
                    Console.WriteLine("OMG");
                    p.score += 1;
                    p.money += prop.bet;
                }
                else if (outcome == c[2])
                {
                    //p.money -= prop.bet;
                    Console.WriteLine("OMG");
                }
                if (p.score > p.highScore)
                {
                    p.highScore += 1;
                }
                z = UIF.PromptLine(c[8]);
            }
        }
Пример #15
0
        public static void SentenceType()
        {
            string input2 = UIF.PromptLine("Please enter a string:");

            if (input2 [input2.Length - 1] == '.')
            {
                Console.WriteLine("The string is a declarative sentence.");
            }
            else
            {
                if (input2[input2.Length - 1] == '!')
                {
                    Console.WriteLine("The string is an exclamatory sentence.");
                }
                else
                {
                    Console.WriteLine("The string is an interrogative sentence.");
                }
            }
        }
Пример #16
0
        //play a game of blackjack, print out the player and dealer's hand and sum after each hit, print whether the player
        //wins, loses or ties.
        static string Play()
        {
            int playerSum = 0;                              //sum of all the players cards
            int dealerSum = 0;                              //sum of all the dealers cards

            int[]         usedCards  = new int[13];         //number cards of each number used
            List <string> runOut     = new List <string>(); //numbers for which all 4 cards have been used
            List <string> hand       = new List <string>(); //all the players cards
            List <string> dealerHand = new List <string>(); //all the dealers cards
            string        game       = "running";           //tells whether the game is running or to quit out

            playerSum = AddCard(hand, playerSum, usedCards, runOut);
            playerSum = AddCard(hand, playerSum, usedCards, runOut);
            dealerSum = AddCard(dealerHand, dealerSum, usedCards, runOut);//
            dealerSum = AddCard(dealerHand, dealerSum, usedCards, runOut);
            Display(hand, dealerHand, playerSum, dealerSum);
            while ((playerSum < 21) && (dealerSum < 21) && (game == "running"))
            {
                string move = UIF.PromptLine("Enter h for hit or s and then enter for stay");
                if ((move == "h") || (playerSum == 0))
                {
                    playerSum = AddCard(hand, playerSum, usedCards, runOut);
                    dealerSum = AddCard(dealerHand, dealerSum, usedCards, runOut);
                    Display(hand, dealerHand, playerSum, dealerSum);
                }
                else
                {
                    Outcome(playerSum, dealerSum, game);
                    game = "done";
                }
            }
            if ((playerSum >= 21) || (dealerSum >= 21))
            {
                return(Outcome(playerSum, dealerSum, game));
            }
        }
Пример #17
0
		public static void Main ()
		{
			List<IGame> games = new List<IGame> (); //games list
			games.Add (new oneBid (); //One Bid game that starts off the game
			games.Add (new pricingGames ()); //pricing game that comes after
			games.Add (new showcaseShowdown ()); //showcase showdown game (spinning the wheel)
			games.Add (new theShowcase ()); //final game 

			int totScore = 0;//total score set to zero

			Console.WriteLine ("Welcome to....");
			Console.WriteLine ("THE PRICE IS RIGHT");
			string name = UIF.PromptLine ("Who do we have the pleasure with playing today with?");
			Console.WriteLine ("Welcome, {0}!", name);

			for (int x = 0; x <= 4; x++) {//loop that runs all the games and avoids redundant code
				totScore = totScore + getGame (x, games).Play ();//plays each game and adds score of each to the total score
				Console.WriteLine (" ");
			}

			Console.WriteLine ("Thanks for playing, {0}!", name);//thanks the user for playing
			Console.WriteLine ("Your total score is " + totScore + "!");//displays the score
			//to play game as long as user wants to play, just add a while loop
		}
Пример #18
0
        /// Return a double entered by the user.  Catch input
        /// errors, and keep promping the user until a legal
        /// decimal entry is made.  Return the corresponding double.  .
        static double PromptDouble(string prompt)
        { //FIX so loops until legal
            string nStr = UIF.PromptLine(prompt).Trim();

            return(double.Parse(nStr));
        }
Пример #19
0
        static void Main() //testing routine
        {
            string s = UIF.PromptLine("Enter a line: ");

            OneCharPerLine(s);
        }
Пример #20
0
        /// Get data, print remainder results
        static void DoSTwice()
        {
            string s = UIF.PromptLine("Enter string: ");

            ShowTwice(s);
        }
Пример #21
0
        static void Main() //testing routine
        {
            string s = UIF.PromptLine("Enter a line: ");

            Console.WriteLine("Reversed is:\n{0}", Reverse(s));
        }
Пример #22
0
        // Play all games and keep score.
        public double Play()           // exactly matches heading in Game interface
        {
            //put in the code for this game here
            double score = 0;            //keeps track of score and is set to zero

            //intro to game
            Console.WriteLine("To start us off, let's play a game of One Bid!");
            Console.WriteLine("You have to guess the price of the item without going over!");

            //ask the user to guess the price of the item
            Console.WriteLine("The item is called a {0}", objPrice);
            int userPrice = UIF.PromptLine("Please enter what you think the item is valued at: ");

            //checks if the player went over
            if (Check(userPrice) == true)
            {
                //informs the user that they went over in price
                Console.WriteLine("Oh! You went over, let's try another item.");
                //recursion to repeat this funciton
                Play();
            }

            //the computer picks for how much they think its worth.
            //we can tweak these later to add more of an algorithmic approach to their guesses
            int pick0 = rnd.Next(objPrice + 500);
            int pick1 = rnd.Next(objPrice + 300);
            int pick2 = rnd.Next(objPrice + 100);

            //checks the difference between the guesses for all the guesses
            int diffUser = objPrice - userPrice;
            int diffP0   = objPrice - pick0;
            int diffP1   = objPrice - pick1;
            int diffP2   = objPrice - pick2;

            if (Check(pick0) == true && Check(pick1) == true && Check(pick2) == true && Check(userPrice))
            {
                //informs the user that everyone went over
                Console.WriteLine("Oh no! Everyone went over, let's try agian.");
                //calls the function again
                Play();
            }

            if (Check(pick0) == true && Check(pick1) == true && Check(pick2) == true)
            {
                //informs the user that everyone went over
                Console.WriteLine("Everyone except for you went over, you win!");
                //retrns the dollar amount of what the user got, including the bonus if they got the exact number
                return(objPrice + Bonus(userPrice, objPrice));                 //must return double score
            }


            //checks if the user was the lowest price (best price)
            if (diffUser > diffP1 || diffUser > diffP0 || diffUser > diffP2)
            {
                //tells the user that they did not win this round
                Console.WriteLine("Sorry, you did not win. Please try again.");
                //recursion to repeat this function
                Play();
            }
            else
            {
                //informs the user on winning the game
                Console.WriteLine("Congradulations! You won this round.");
                Console.WriteLine("The correct amount was {0} for the {1} and you guessed {2}", objPrice, objName, userPrice);
            }
            //retrns the dollar amount of what the user got, including the bonus if they got the exact number
            return(objPrice + Bonus(userPrice, objPrice));             //must return double score
        }
Пример #23
0
        public static void Main(string[] args)
        {
            string s = UIF.PromptLine("Enter a line: ");

            Console.WriteLine(HasDoubleChar(s))
        }
Пример #24
0
        static void Main() //testing routine
        {
            string s = UIF.PromptLine("Enter a line: ");

            PrintVowels(s);
        }
Пример #25
0
        public static void Main(string[] args)
        {
            //initilization
            double ex0;
            double lab0;
            double hw0;
            double pro0;
            double par0;

            double left0 = 100;

            double ex1;
            double lab1;
            double hw1;
            double pro1;
            double par1;

            double ex2;
            double lab2;
            double hw2;
            double pro2;
            double par2;

            double fin;
            string fing;

            bool done = false;

            while (done == false)
            {
                //intro
                Console.WriteLine("Welcome to The Grade Calculator.");
                Console.WriteLine("Follow the directions to find out what your grade is.");
                string name = UIF.PromptLine("What is your name: ");
                //Console.WriteLine ("What is your name?");
                //string name = Console.ReadLine ();

                Console.WriteLine("Hello, {0}.", name);
                Console.WriteLine(" ");


                //asking for exam weights
                do
                {
                    ex0 = UIF.PromptInt("What are your exams weighted? (You have " + left0 + "% left): ");
                    //string ex = Console.ReadLine ();
                    //ex0 = double.Parse (ex);
                    left0 -= ex0;

                    lab0 = UIF.PromptInt("What are your labs weighted? (You have " + left0 + "% left): ");
                    //string lab = Console.ReadLine ();
                    //lab0 = double.Parse (lab);
                    left0 -= lab0;

                    hw0 = UIF.PromptInt("What is your homework weighted? (You have " + left0 + "% left): ");
                    //string hw = Console.ReadLine ();
                    //hw0 = double.Parse (hw);
                    left0 -= hw0;

                    pro0 = UIF.PromptInt("What are your projects weighted? (You have " + left0 + "% left): ");
                    //string pro = Console.ReadLine ();
                    //pro0 = double.Parse (pro);
                    left0 -= pro0;

                    par0 = UIF.PromptInt("What is your participation weighted? (You have " + left0 + "% left): ");
                    //string par = Console.ReadLine ();
                    //par0 = double.Parse (par);
                    left0 -= par0;

                    double sum0 = (ex0 + lab0 + hw0 + pro0 + par0);

                    if (sum0 != 100.00)
                    {
                        Console.WriteLine("Your number don't add up 100%, check that out and try again.");
                        left0 = 100;
                    }
                } while((ex0 + lab0 + hw0 + pro0 + par0) != 100);

                //asking for user's grades
                Console.WriteLine(" ");
                Console.WriteLine("Enter your grade on exams.");
                double n0 = UIF.PromptDouble("How many total grades do you have: ");
                ex1 = findAverage(n0);
                if (ex1 > 1)
                {
                    Console.WriteLine("Calculated average exam grade = {0:F1}", ex1);
                }
                Console.WriteLine(" ");
                //string e = Console.ReadLine ();
                //ex1 = double.Parse (e);

                Console.WriteLine("Enter your grade on labs.");
                double n1 = UIF.PromptDouble("How many total grades do you have: ");
                lab1 = findAverage(n1);
                if (lab1 > 1)
                {
                    Console.WriteLine("Calculated average labs grade = {0:F1}", lab1);
                }
                Console.WriteLine(" ");
                //string l = Console.ReadLine ();
                //lab1 = double.Parse (l);

                Console.WriteLine("Enter your grade on homework.");
                double n2 = UIF.PromptDouble("How many total grades do you have: ");
                hw1 = findAverage(n2);
                if (hw1 > 1)
                {
                    Console.WriteLine("Calculated average homework grade = {0:F1}", hw1);
                }
                Console.WriteLine(" ");
                //string h = Console.ReadLine ();
                //hw1 = double.Parse (h);

                Console.WriteLine("Enter your grade on projects.");
                double n3 = UIF.PromptDouble("How many total grades do you have: ");
                pro1 = findAverage(n3);
                if (pro1 > 1)
                {
                    Console.WriteLine("Calculated average projects grade = {0:F1}", pro1);
                }
                Console.WriteLine(" ");
                //string pr = Console.ReadLine ();
                //pro1 = double.Parse (pr);

                Console.WriteLine("Enter your grade on participation.");
                double n4 = UIF.PromptDouble("How many total grades do you have: ");
                par1 = findAverage(n4);
                if (par1 > 1)
                {
                    Console.WriteLine("Calculated average participation grade {0:F1}", +par1);
                }
                Console.WriteLine(" ");
                //string pa = Console.ReadLine ();
                //par1 = double.Parse (pa);

                //calculations
                ex2  = (ex0 * ex1) / 1000.00;
                lab2 = (lab0 * lab1) / 1000.00;
                hw2  = (hw0 * hw1) / 1000.00;
                pro2 = (pro0 * pro1) / 1000.00;
                par2 = (par0 * par1) / 1000.00;

                double sum2 = ex2 + lab2 + hw2 + pro2 + par2;

                fin = sum2 * 10.0;

                if (fin > 93)
                {
                    fing = "A";
                }
                else if (fin > 90)
                {
                    fing = "A-";
                }
                else if (fin > 87)
                {
                    fing = "B+";
                }
                else if (fin > 83)
                {
                    fing = "B";
                }
                else if (fin > 80)
                {
                    fing = "B-";
                }
                else if (fin > 77)
                {
                    fing = "C+";
                }
                else if (fin > 73)
                {
                    fing = "C";
                }
                else if (fin > 70)
                {
                    fing = "C-";
                }
                else if (fin > 67)
                {
                    fing = "D+";
                }
                else if (fin > 63)
                {
                    fing = "D";
                }
                else if (fin > 60)
                {
                    fing = "D-";
                }
                else
                {
                    fing = "F";
                }

                //answer to their question

                Console.WriteLine("{0}, your final grade is a {1}%.", name, fin);
                Console.WriteLine("You got an {0} in the class.", fing);
                Console.WriteLine("Press Y to do another calculation");
                string result = Console.ReadLine();

                //check to see if user wants to do another calculation
                if ((result).Equals("y"))
                {
                    done  = false;
                    left0 = 100;
                }
                else if ((result).Equals("Y"))
                {
                    done  = false;
                    left0 = 100;
                }
                else
                {
                    done = true;
                }
            }
            Environment.Exit(0);
        }
Пример #26
0
        public static void Main(string[] args)
        {
            string input = UIF.PromptLine("Please enter a string:");

            ShowLength(input);
        }
Пример #27
0
        /// Return an int entered by the user.  Catch input
        /// errors, and keep promping the user until a
        /// legal entry is made.  Return the corresponding int.
        static int PromptInt(string prompt)
        { //FIX so loops until legal
            string nStr = UIF.PromptLine(prompt).Trim();

            return(int.Parse(nStr));
        }