Jump to content

Aaaaaaaaa

Member
  • Posts

    20
  • Joined

  • Last visited

Awards

This user doesn't have any awards

Aaaaaaaaa's Achievements

  1. Where should I insert what you have mentioned in my code?
  2. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace YourLastName_Lab7 { public partial class FormMain : Form { /// <summary> /// Initialize the graphical user interface of the form /// </summary> public FormMain() { InitializeComponent(); } /// <summary> /// Saves the contact to a file /// </summary> private void buttonAdd_Click(object sender, EventArgs e) { // validate required fields string name = this.textBoxName.Text.Trim(); string address = this.textBoxAddress.Text.Trim(); if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(address)) { MessageBox.Show("The name and address is required."); return; } // Open a file and save it StreamWriter sw = new StreamWriter("addresses.txt", true); sw.WriteLine(name); sw.WriteLine(address + "\n"); sw.Flush(); sw.Close(); // Display the result in the richtextbox this.richTextBoxContacts.AppendText(name + "\n" + address + "\n\n"); this.textBoxName.Clear(); this.textBoxAddress.Clear(); } } } Above is my code for this question below! But for some reason I am having problems executing. Can someone please review it and see what is wrong. Thank You! Write a Windows application that gets names and e-mail addresses from the user and displays a list of all of the user's contacts. Each time the user enters a new contact, he/she should able to see it added to a list of previously stored contacts. For example, in the following sample output below, after the user clicks the "Add Contact" button, the list will include John Mann's contact information at the bottom.When designing the GUI, consider initially disabling the e-mail textbox and the button until all information is entered. Redisable them when the button is clicked. Note that you can also use the Tab Index property of GUI objects to set their order of use. Pseudocode: When the "Add Contact" button is clicked Open an output file stream for appending Write the contact's name and e-mail address to the file Close the file stream Clear the list Open an input file stream for reading Add each line of the file to the list Close the file stream When the form closes Close the input and output file streams
  3. Okay I understand a little bit. However I am getting errors and then a dialog box comes up saying it cant run because of my debugging target?
  4. int count = 0; int choice = Convert.ToInt32(guess); if (guess.Text != string.Empty) { // set counter to keep track of how many tries // should this be done by a loop or will it count without a loop? count++; //compare user input against random number //Can’t import the random number for comparision if (choice < answer) { Evaluate.Visible = false; lblMessage.Visible = true; lblMessage.Text = "Too Low!"; Clear.Visible = true; BackColor = Color.LightSeaGreen; } else if (choice > answer) { Evaluate.Visible = false; lblMessage.Visible = true; lblMessage.Text = "Too High!"; Clear.Visible = true; BackColor = Color.SlateBlue; } else { //Display correct message along with how many times it took to get it MessageBox.Show(" Eso es CORRECTO! It took you {0} tries. ", count); } } } private void Clear_Click(object sender, EventArgs e) { guess.Text = ""; Evaluate.Visible = true; lblMessage.Visible = false; Clear.Visible = false; BackColor = Color.PowderBlue; } } } private int answer; private int count; public game() { InitializeComponent(); //Generate Random number between 1 and 100 Random random= new Random(); // no need for num1 and num2, it's just as random answer = random.Next(1,101); } public partial class game : Form { int answer; public game() { } }
  5. Write a Windows application that randomly generates a number from 0 through 100. Prompt the user to guess the number. Let the user know if the guess is too low, too high, or is the correct number. Give the user another chance to guess the number. The user keeps guessing until he or she gets it correct. Form constructor method Randomly pick a target number between 0 and 100 Evaluate Button Click Event Handler Method If the guess text box is not blank Pull the guess from the text box Add 1 to the number of guesses If the guess is less than the target Make the Evaluate button invisible Change the label message to "Too Low!!" Make the label message visible Change the background color of the form to LightSeaGreen Make the Try Again button visible Else if the guess is greater than the target Make the Evaluate button invisible Change the label message to "Too High!!" Make the label message visible Change the background color of the form to SlateBlue Make the Try Again button visible Else Display a message indicating the user guessed correctly and display the number of guesses it took. End-If End-If Try Again Button Click Event handler Clear the guess text box Make the label message and Try Again buttons invisible Make the Evaluate button visible
  6. When i try to run it in Visual Studio, the part where is says display below average, name and score nothing comes up. It does not process at all. That is my problem just the last part nothing else.
  7. I didn't use pastebin though. This is an assignment that I need help on. So wtf are you talking about?
  8. This is my code: double[] scoresArray = new double[100]; string[] playersArray = new string[100]; char reloop = 'Y'; int count = 0; do { double averageScore = 0; double belowAverage = 0; int numbers = 0; InputData(ref scoresArray, ref playersArray, ref count); DisplayPlayerData(ref scoresArray, ref playersArray, ref count); CalculateAverageScore(ref scoresArray, ref playersArray, ref count); Console.ReadLine(); DisplayBelowAverage(ref scoresArray, ref playersArray, ref count); reloop = Convert.ToChar(Console.ReadLine()); reloop = char.ToUpper(reloop); } while (reloop != 'Y'); } static void InputData(ref double[] scoresArray, ref string[] playersArray, ref int count) { while (playersArray.Length <= 100) { Console.Write("Please enter the player's name: " + "((Q to Quit)) "); playersArray[count] = Console.ReadLine(); if (playersArray[count] == "Q" || playersArray[count] == "q") { break; } Console.Write("Please enter " + playersArray[count] + " scores: "); scoresArray[count] = Convert.ToDouble(Console.ReadLine()); count++; } } static void DisplayPlayerData(ref double[] scoresArray, ref string[] playersArray, ref int count) { Console.WriteLine("Player Score"); for (int i = 0; i < count; i++) { Console.WriteLine("{0,-15} {1,-6}", playersArray, scoresArray); } } static void CalculateAverageScore(ref double[] scoresArray, ref string[] playersArray, ref int count) { int total = 0; double average = 0; { foreach (int s in scoresArray) total += s; average = total / scoresArray.Length; Console.Write("Average score is : ", average); Console.ReadLine(); } } static void DisplayBelowAverage(ref double[] scoresArray, ref string[] playersArray, ref int count) { Console.Write("Players who score below average: "); Console.Write("Name Score"); Console.Read(); foreach (int val in scoresArray) { if (val <average) { Console.WriteLine(val); This is the question Write a program to determine statistics for a video game tournament. The user will input names and scores of all tournament players. The program will calculate the average score and display the players who scored below average. The program will implement these functions: Main(): Declares variables for the number of players and average score, and two arrays of size 100: one to store player names and the other to store their respective scores. Calls the following functions in sequence, passing necessary parameters by reference: InputData( ): Gets player names and scores from the user and stores them into the two arrays for an unknown number of players up to 100. DisplayPlayerData(): Displays each player's name and score. CalculateAverageScore( ): Calculates the average score and returns it by value. DisplayBelowAverage( ): Displays the names and scores of players who scored below average. Sample output: Enter Player Name (Q to quit): Bob Enter score for Bob: 3245 Enter Player Name (Q to quit): Sue Enter score for Sue: 1098 Enter Player Name (Q to quit): Dave Enter score for Dave: 8219 Enter Player Name (Q to quit): Pat Enter score for Pat: 3217 Enter Player Name (Q to quit): Q Name Score Bob 3245 Sue 1098 Dave 8219 Pat 3217 Average Score: 3944.75 Players who scored below average Name Score Bob 3245 Sue 1098 Pat 3217 Press any key to continue . . . Main Function Declare player and score arrays, and variables for number of players and average score. Call the InputData( ) function, passing arrays and number of players variable by reference Call the DisplayPlayerData( ) function, passing arrays and number of players variable by reference Call the CalculateAverageScore( ) function, passing arrays and number of players by reference. Store returned value in average variable. Display the average score Call the DisplayBelowAverage( ) function, passing arrays and number of players variable by reference, passing average variable by value InputData function Loop while the number of players is less than the length of the array Prompt for the player's name If the user entered Q, break out of the loop Prompt the user for the player's score Add 1 to the number of players DisplayPlayerData function Loop to display the name and score of each player CalculateAverageScore function Loop to add up the scores Divide by the number of players to calculate the average score Return the average score to main DisplayBelowAverage function Loop to display the names and scores of all players who scored below the average score
  9. Ohh Okay! I knew I was on the right track, just was not sure.
  10. Write a program to alphabetize a list of last names. The user will input an undetermined number of last names. The program will display the number of names entered and alphabetized lists of the names in ascending (A-Z) and descending (Z-A) order. Your program will store the names in an ArrayList object. It will use various ArrayList properties and methods to implement the program requirements. Sample output: Enter a last name: Roberts Keep going? (Y/N): y Enter a last name: DeLay Keep going? (Y/N): y Enter a last name: Foreman Keep going? (Y/N): y Enter a last name: Ganguly Keep going? (Y/N): n 4 last names entered Names in Ascending Order DeLay Foreman Ganguly Names in Descending Order Roberts Ganguly Foreman DeLay Don't try to write too much at a time! First, write an outline in comments based on the requirements and the pseudocode. Then, work on instantiating an ArrayList object, followed by implementing the loop that will get user input. As always, keep things simple and implement incrementally. Review the list of ArrayList methods and properties in the textbook and experiment with the ones you think you'll need. Pseudocode Main function Instantiate ArrayList object Loop to get last names, until user wants to quit Add each last name to the ArrayList Display the count of the last names Sort the ArrayList Loop to display the names Reverse the order of the ArrayList Loop to display the names Above is the question^ Below is what I have started working on but the names wont process in ascending and descending order. Please help me??? var names = new List<String>(); do { Console.Write("\nEnter name: "); names.Add(Console.ReadLine()); Console.Write("Keep going? (y/n)"); } while (Console.ReadKey().KeyChar == 'y'); Console.WriteLine( "\n{0} names entered." + "\nNames in ascending Order\n"); names.Sort(); foreach (var name in names) { Console.WriteLine(name); } Console.WriteLine("\nNames in descending Order\n"); names.Reverse(); foreach (var name in names) { Console.WriteLine(name);
  11. Yes we have to enter that information in Visual Studio. We have to enter in the information, write our own code with the hopes of achieving the output. This is the question given to me below, this is all the information I was given. Requirements Your mission: Write a program that translates a TV channel (1 through 10) in your area to its respective call sign. For example, in the New York metropolitan area, channel 2 translates to WCBS. If a channel is unused in your area, tell the user that this is the case. Sample output from program: Translate TV Channel Number to Call Sign Enter channel number: 1 Channel 1 is undesignated in your area Enter channel number: 2 Call sign for channel 2 is WCBS Enter channel number: 6 Call sign for channel 6 is WRNNDT Tips Best practice: Put yourself in the place of the program. What steps would you personally need to perform in order to process a channel translation yourself? Write out those steps on paper as pseudocode and/or in Visual Studio as C# comments, and then implement them one by one, testing as you go. Remember to not write too much at one time. Always add and test functionality incrementally! Pseudocode: Although there are several valid ways to write the program, the following is an outline of one way to design the overall logic. Declare variables for channel and call sign Get channel number from user Use appropriate decision structure to translate number to call sign If number is valid in area Print out translation If not Tell user this is the case
  12. I would agree it needs to be polished, but it is definitely better than netflix!
  13. Okay! What about what comes ahead of that? Declaring the variables?
×