using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Assignment4 { class Program { static void Main(string[] args) { Program p = new Program(); string quit = "y"; while (quit != "n") { p.CreateArrays(); Console.WriteLine("Do you want start over? n to quit"); quit=Console.ReadLine(); quit.ToLower(); } Console.ReadKey(); } private void CreateArrays() { Console.WriteLine("How many Grades do you want to enter"); int number = int.Parse(Console.ReadLine()); double[] grades = new double[number]; double[] credits = new double[number]; FillArrays(grades, credits); } private void FillArrays(double[] grades, double[] credits) { for (int counter = 0; counter < grades.Length; counter++) { double grade = 0; do { Console.WriteLine("Enter a Grade"); grade = double.Parse(Console.ReadLine()); if (grade <= 0 || grade > 4) { Console.WriteLine("Grades must be between 0 and 4"); } } while (grade <= 0 || grade > 4); grades[counter]=grade; Console.WriteLine("Enter the Credits"); credits[counter] = double.Parse(Console.ReadLine()); }//end for CalculateGPA(grades, credits); }//end fill arrays private void CalculateGPA(double[] grades, double[] credits) { double totalCredits = 0; double weight = 0; for (int counter = 0; counter < grades.Length; counter++) { weight+=grades[counter] * credits[counter]; totalCredits += credits[counter]; }//end for double gpa = weight / totalCredits; Console.WriteLine("Your GPA is {0:F1}", gpa); } }//end class }
and here is the code for doing random numbers
static void Main(string[] args) { Random rand = new Random(); int number = rand.Next(1, 10); Console.WriteLine(number); Console.ReadKey(); }
No comments:
Post a Comment