Question

Fix program errors and improve code Visual Studio C# Console App (.NET Framework) Task The program...

Fix program errors and improve code

Visual Studio C# Console App (.NET Framework)

Task

The program must allow for the teacher to either enter a predetermined number of scores
(e.g. 10 exam scores), to keep allowing them to enter in scores until they are
finished. You will need to convert these scores to a percentage then store these in a list.

You will perform some calculations on these results and also display the contents of
the list (percentage values) back to the user. You will need to provide evidence showing that
you have tested your across a range of inputs and the matching end results. This could be in
the form of multiple screen shots and/or a table showing all your tested inputs and the
corresponding results etc.

[If the user enters the raw scores: 15, 50, 70, 25 the program will convert and store
these as percentages as 20%, 68%, 95% and 34% respectively (test is out of 50). The
program will then return the average of 54%, maximum 95%, minimum 20%, number of
entries 4 and the sum of 216%. The sorted list is also displayed, e.g. 20%, 34%, 68%, 95%.
Your program should also provide descriptions of what your code aims to achieve through
good commenting (notes). Add any other useful enhancements that you wish to use to help
showcase your skills from within this topic.]

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace Assessment

{

class Program

{

static void Main(string[] args)

{

List <int> testResults = new List <int>();

const int MIN = 0; //Determine the Maximum and Minimum value range of the test

const int MAX = 75;

int userInput; //Determines the variables

int userInput2;

bool numOfEntries;

bool numOfResults;

Console.WriteLine("How many Science Test Scores do you want to enter?");   

numOfEntries = int.TryParse(Console.ReadLine(), out userInput);

while (numOfEntries == false || userInput < MIN)   

if (numOfEntries == false)

{

Console.WriteLine("Please enter a valid number!");

numOfEntries = int.TryParse(Console.ReadLine(), out userInput);

}

else if (userInput < MIN)

{

Console.WriteLine("Please enter a valid number above 0!");

numOfEntries = int.TryParse(Console.ReadLine(), out userInput);

}

for (int i = 0; i < userInput; i++) //Repeat as much times as the user inputs

{

Console.WriteLine("Please enter your test result!");

numOfResults = int.TryParse(Console.ReadLine(), out userInput2);

while (numOfResults == false || userInput2 >= MAX || userInput2 < MIN)   

if (numOfResults == false)

{

Console.WriteLine("Please enter a valid number!");

numOfResults = int.TryParse(Console.ReadLine(), out userInput2);

}

else if (userInput2 >= MAX)

{

Console.WriteLine("Please enter a valid number below 74!");

numOfResults = int.TryParse(Console.ReadLine(), out userInput2);

}

else if (userInput2 < MIN)

{

Console.WriteLine("Please enter a valid number above 0!");

numOfResults = int.TryParse(Console.ReadLine(), out userInput2);

}

testResults.Add(userInput2 / MAX * 100);

}

testResults.Sort();

Results(testResults);

Console.WriteLine("Your list of numbers are as follows: ");

Console.ReadKey();

}

static void Results(List<int> resultsInAMMSC) //AMMSN is Average, Maximum, Minimum, Sum and Count

{

Console.WriteLine("Average :" + resultsInAMMSC.Average() + "%"); //Shows the user what their inputs are in AMMSN

Console.WriteLine("Maximum :" + resultsInAMMSC.Max() + "%");

Console.WriteLine("Minimum :" + resultsInAMMSC.Min() + "%");

Console.WriteLine("Sum :" + resultsInAMMSC.Sum() + "%");

Console.WriteLine("results :" + resultsInAMMSC.Count());

}

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new Console Application in C# is created using Visual Studio 2017 with name "Assessment".This application contains a program with name "Program.cs".Below are the details of this class.

Program.cs :

//namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//application namespace
namespace Assessment
{
class Program //Class
{
static void Main(string[] args)//Main method
{
List<double> testResults = new List<double>();
const int MIN = 0; //Determine the Maximum and Minimum value range of the test
const int MAX = 74;//max
int userInput; //Determines the variables
int userInput2;
bool numOfEntries;
bool numOfResults;
//asking to enter number of score
Console.WriteLine("How many Science Test Scores do you want to enter?");
numOfEntries = int.TryParse(Console.ReadLine(), out userInput);//reading and parsing input
while (numOfEntries == false || userInput < MIN)
if (numOfEntries == false) //for invalid input
{
Console.WriteLine("Please enter a valid number!");
numOfEntries = int.TryParse(Console.ReadLine(), out userInput);

}
else if (userInput < MIN)
{
Console.WriteLine("Please enter a valid number above 0!");
numOfEntries = int.TryParse(Console.ReadLine(), out userInput);
}

for (int i = 0; i < userInput; i++) //Repeat as much times as the user inputs
{
Console.WriteLine("Please enter your test result!");
numOfResults = int.TryParse(Console.ReadLine(), out userInput2);
while (numOfResults == false || userInput2 >= MAX || userInput2 < MIN)
  
if (numOfResults == false)//for invalid input
{
Console.WriteLine("Please enter a valid number!");
numOfResults = int.TryParse(Console.ReadLine(), out userInput2);
}
else if (userInput2 >= MAX)
{
Console.WriteLine("Please enter a valid number below 74!");
numOfResults = int.TryParse(Console.ReadLine(), out userInput2);
}
else if (userInput2 < MIN)
{
Console.WriteLine("Please enter a valid number above 0!");
numOfResults = int.TryParse(Console.ReadLine(), out userInput2);
}
//add score in the list
testResults.Add(Math.Round(userInput2 / (double)MAX * 100));
  
}
//sort the list
testResults.Sort();
Results(testResults);//call method
Console.WriteLine("Your list of numbers are as follows: ");
//display numbers
foreach (var num in testResults)
{
Console.WriteLine(num);//display test scores
}
Console.ReadKey();
}
//Method defination
static void Results(List<double> resultsInAMMSC) //AMMSN is Average, Maximum, Minimum, Sum and Count
{
Console.WriteLine("Average :" + resultsInAMMSC.Average() + "%"); //Shows the user what their inputs are in AMMSN
Console.WriteLine("Maximum :" + resultsInAMMSC.Max() + "%");//display Max
Console.WriteLine("Minimum :" + resultsInAMMSC.Min() + "%");//display min
Console.WriteLine("Sum :" + resultsInAMMSC.Sum());//display sum
Console.WriteLine("results :" + resultsInAMMSC.Count());//display count
}
}
}

======================================================

Output : Run application using F5 and will get the screen as shown below

Screen 1 :

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
Fix program errors and improve code Visual Studio C# Console App (.NET Framework) Task The program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (C#, Visual Studio) I need help modifying my program code to accommodate repeated numbers. For example,...

    (C#, Visual Studio) I need help modifying my program code to accommodate repeated numbers. For example, if a user inputs a repeated number the program should regenerate or ask to enter again. If needed, here is the program requirements: Create a lottery game application. Generate four random numbers, each between 1 and 10. Allow the user to guess four numbers. Compare each of the user’s guesses to the four random numbers and display a message that includes the user’s guess,...

  • Fix the code using C# shown below to show the repitition as seen on the example...

    Fix the code using C# shown below to show the repitition as seen on the example screenshot: (Invalid error must repeat): using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Program { class Program { static void Main(string[] args) { double num, count = 0; double Tax = 0.00, ship = 5.00, sum = 0.00; double grandtotal; char line; //Set run =true bool run=true; do { //read amount of item Console.WriteLine("What is the amount of item : "); //read in...

  • I am writing a console application in C#. It is a receipt where the user inputs...

    I am writing a console application in C#. It is a receipt where the user inputs the item then quantity and then price per item. It is then validated through regular expressions. I need to put this in a multidimensional array to print out (command line print), like each row would have a columns for item, quantity, price and then subtotal for each item, but cannot figure it out. I also need the regular expression in a do while loop...

  • I need help with the following assignment: Write an application named DailyTemps that continuously prompts a...

    I need help with the following assignment: Write an application named DailyTemps that continuously prompts a user for a series of daily high temperatures until the user enters a sentinel value of 999. Valid temperatures range from -20 through 130 Fahrenheit. When the user enters a valid temperature, add it to a total; when the user enters an invalid temperature, display the error message: Valid temperatures range from -20 to 130. Please reenter temperature. Before the program ends, display the...

  • So I am creating a 10 question quiz in Microsoft Visual Studio 2017 (C#) and I...

    So I am creating a 10 question quiz in Microsoft Visual Studio 2017 (C#) and I need help editing my code. I want my quiz to clear the screen after each question. It should do one question at a time and then give a retry of each question that was wrong. The right answer should appear if the retry is wrong. After the 1 retry of each question, a grade should appear. Please note and explain the changes you make...

  • Hello in C#. I need help understanding and knwoing what i missed in my program. The...

    Hello in C#. I need help understanding and knwoing what i missed in my program. The issue is, the program is supposed to have user input for 12 family members and at the end of the 12 it asks for user to input a name to search for. When i put a correct name, it always gives me a relative not found message. WHat did i miss. And can you adjust the new code so im able to see where...

  • C# Arrays pne and Look at the code below Notice that the program has one class...

    C# Arrays pne and Look at the code below Notice that the program has one class called Tournament. . It defines an integer array called scores to hold all the scores in the tournament .The constructor for the class then actually creates the array of the required size. class Tournament int[ ] scores; const int MAX = 6; // define scores as an integer array // set a constant size public static void Main() //program starts executing here Tournament myTournament...

  • In c++ programming, can you please edit this program to meet these requirements: The program that...

    In c++ programming, can you please edit this program to meet these requirements: The program that needs editing: #include <iostream> #include <fstream> #include <iomanip> using namespace std; int cal_avg(char* filenumbers, int n){ int a = 0; int number[100]; ifstream filein(filenumbers); if (!filein) { cout << "Please enter a a correct file to read in the numbers from"; }    while (!filein.eof()) { filein >> number[a]; a++; } int total = number[0]; for (a = 0; a < n; a++) {...

  • Need code written for a java eclipse program that will follow the skeleton code. Exams and...

    Need code written for a java eclipse program that will follow the skeleton code. Exams and assignments are weighted You will design a Java grade calculator for this assignment. A user should be able to calculate her/his letter grade in COMS/MIS 207 by inputting their scores obtained on worksheets, assignments and exams into the program. A skeleton code named GradeCompute.java containing the main method and stubs for a few other methods, is provided to you. You must not modify/make changes...

  • I need to create a code for this prompt: In this project we will build a...

    I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT