Question
Variables, Expressions, and User Input The code must be written in C# In this lab, you will work with assigning values to variables of multiple
Variables, Expressions, and User Input
The code must be written in C#
In this lab, you will work with assigning values to variables of multiple types that you have declared. Additionally, you will begin to play with operators to build more complex expressions.
YOUR PROGRAM
For your program, you will write a simple utility to calculate the average grade of three assignments for a student, and display the results.
Create a new source file for this lab. You should first declare 6 variables inside of the main, as follows:
1. A variable that will store a students first name and another to hold their last name.
2. Three variables to hold three assignment scores. Potential values to be assigned to these variables will be whole numbers between 0 and 100, so select an appropriate data type.
3. An int variable to store the total number of assignments. This variable should be initialized to 3.
4. A final variable to hold the average of the three scores. While the scores will all be whole numbers, the average should be able to accommodate a decimal value if necessary.
Variable names are up to you, but you should attempt to choose names that meaningfully describe the purpose of each variable.
Once you have your variables declared, you should next collect values to initialize the two strings (for first and last name) and the three integers (for the three scores) from the user. Begin by asking the user to enter the students first name. Capture the input and store it in the variable you declared for the first name. Repeat the process for their last name.
With the name collected, its time to initialize the three assignment score variables. For each, first display a prompt to the user, asking them to enter a score for the student between 0 and 100. In each prompt, you should include the students first name. This can be seen demonstrated in the sample screenshot provided below.
After each prompt, retrieve the users input, converting it as necessary to store it in the respective variable. When testing this portion of your code, remember that valid values for the data should be whole numbers. What would happen if you entered a decimal number instead?
Finally, write an assignment statement to initialize your average variable to the average of the three scores. When writing the expression, be sure to consider the order of operations involved, as well as the data types. You will first need to add the three integer scores together, and only then divide that sum by the variable storing the total number of assignments. The general form of the equation should look something like the following (replacing the [] fields with the names of your variables)
[Average] = ( [Score1] + [Score2] + [Score3] ) / [AssignmentCount];
Because both the individual scores and the count of assignments are integer values, this expression would default to integer division. To solve this, you will need to cast one side of the division expression to a double to ensure proper floating point division.
After youve calculated the average, output the result, along with the full name of the student, as seen in the sample output below. For full credit, you should use the newly-introduced format strings, and not string concatenation, to build the output. Your output should match mine as closely as possible. Specific wording can change, as will the name and values that you test your code with, but the basic form and function should remain the same. If you use the same values as I have, you should get the same result.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started