Question

Modify the C# program to allow it to calculate the average of three numbers instead of...

Modify the C# program to allow it to calculate the average of three numbers instead of the sum. then submit your program to This Drop Box.

C# Program:

using System;

class MainClass {

public static void Main (string[] args) {

Console.WriteLine ("Hello World");

}

}

Homework Answers

Answer #1

//The answer code is compiler dependent the user input may not work in some online compilers.

using System.IO;
using System;

class MainClass
{
public static void Main(string[] args)
{

//taking 3 double values for user input values.

double number1,number2,number3;

//taking 3 input from user   


Console.Write("Enter the First number: ");
number1 = Convert.ToDouble(Console.ReadLine());

Console.Write("\nEnter the Second number: ");
number2 = Convert.ToDouble(Console.ReadLine());

Console.Write("\nEnter the third number: ");
number3 = Convert.ToDouble(Console.ReadLine());


double result = (number1 + number2 + number3) / 3; //calculating average of 3 and storing in result variable.


Console.WriteLine("\nThe average of {0}, {1}, {2}is: {3} ",number1, number2, number3, result);
}
}

Know the answer?
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
Similar Questions
Read in a file "numbers.txt" into a Java program. Sum up all the even numbers over...
Read in a file "numbers.txt" into a Java program. Sum up all the even numbers over 50. Print the result to the console using System.out.println(); The file will only have numbers. code below import java.io.FileNotFoundException; import java.io.FileReader; import java.util.Scanner; public class ReadingFiles { public static void main(String[] args) throws FileNotFoundException { System.out.println(totalEven); } }
JAVA -Consider this program: public class Main { public static void main(String[] args) { String s1...
JAVA -Consider this program: public class Main { public static void main(String[] args) { String s1 = new String("hello"); String s2 = "hello"; String s3 = "hello";    System.out.println(s1 == s3); System.out.println(s1.equals(s3)); System.out.println(s2 == s3); } } When we run the program, the output is: false true true Explain why this is the output, using words and/or pictures.
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*;...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener {     int count;     JButton button;     Clicker() {         super("Click Me");         button = new JButton(String.valueOf(count));         add(button);         button.addActionListener(this);         setSize(200,100);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         setVisible(true);     }     public void actionPerformed(ActionEvent e) {         count++;         button.setText(String.valueOf(count));     }     public static void main(String[] args) { new Clicker(); } } a. add(button);...
PP 8.2 Modify the program from PP 8.1 so that it works for numbers in the...
PP 8.2 Modify the program from PP 8.1 so that it works for numbers in the range between −25 and 25 THIS IS MY CODE! please edit this...Thank you import java.util.Scanner; public class Array { public static void main (String[] args) { Scanner scan = new Scanner (System.in); int[] integs = new int[51]; System.out.println("Enter integers 0-50 [enter -1 to quit]: "); int nums = scan.nextInt(); while (nums != -1 && nums>=0 && nums<=50) { integs[nums]++; nums = scan.nextInt(); } for...
Identify the errors in the following C# program. Write the correct program. Explain the errors. class...
Identify the errors in the following C# program. Write the correct program. Explain the errors. class Program { static Main(string[] args) { int x = 10 Console.WriteLine("{0}" + x); Console.ReadLine(); }
Convert the QuartsToGallons program to an interactive application. Instead of assigning a value to the number...
Convert the QuartsToGallons program to an interactive application. Instead of assigning a value to the number of quarts, accept the value from the user as input. class QuartsToGallonsInteractive {    public static void main(String[] args)    {          // Modify the code below       final int QUARTS_IN_GALLON = 4;       int quartsNeeded = 18;       int gallonsNeeded;       int extraQuartsNeeded;       gallonsNeeded = quartsNeeded / QUARTS_IN_GALLON;       extraQuartsNeeded = quartsNeeded % QUARTS_IN_GALLON;       System.out.println("A job that needs " + quartsNeeded +          " quarts requires " + gallonsNeeded + " gallons...
What will be the output of the given code? using System; class MyProgram { static void...
What will be the output of the given code? using System; class MyProgram { static void Main(string[] args) { try { int a, b; b = 0; a = 5 / b; Console.WriteLine("No exception will occur."); } catch (ArithmeticException e) { Console.WriteLine("Exception occurs."); } finally { Console.WriteLine("Program is executed."); } Console.ReadLine(); } } A Program is executed. B No exception will occur. C Exception occurs. Program is executed. D No exception will occur. Program is executed.
Covert the following Java program to a Python program: import java.util.Scanner; /** * Displays the average...
Covert the following Java program to a Python program: import java.util.Scanner; /** * Displays the average of a set of numbers */ public class AverageValue { public static void main(String[] args) { final int SENTINEL = 0; int newValue; int numValues = 0;                         int sumOfValues = 0; double avg; Scanner input = new Scanner(System.in); /* Get a set of numbers from user */ System.out.println("Calculate Average Program"); System.out.print("Enter a value (" + SENTINEL + " to quit): "); newValue =...
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Assignment06 {    class Program    {...
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Assignment06 {    class Program    {        static void Main(string[] args)        {            int age = 10;            if (age >= 16)            {                Console.WriteLine("Error;Since you are " + age + " years old, you are legally unable to obtain a license.");            }            Console.Write("Hit any key to close"); Console.ReadKey(false);       ...