Answer to Question #344736 in C# for miya

Question #344736

Write a program to find the total and average of a set of numbers entered by a

user. The following provides additional details on how the program should work:

• The program should prompt the user how many numbers they want o

process.

• Once user input is obtained, user will be asked to enter the numbers

used to calculate the total and average repeatedly. (Data validation

must be performed to ensure that the user input is between 1 to 100

inclusive)

• Finally, the total and average calculated will be displayed to the user.


1
Expert's answer
2022-05-25T14:32:49-0400
using System;
class Program
{
    static void Main(string[] args)
    {
        string str = "";
        int Number = 0;
        while (Number == 0)
        {
            Console.Write("Please enter an integer from 1 to 10:");
            str = Console.ReadLine();
            if (int.TryParse(str, out Number))
                if (Number >= 1 && Number <= 10)
                {
                    int[] nums = new int[Number];
                    int i = 0;
                    int value = 0;
                    while (i < Number)
                    {
                        Console.Write("Please enter an integer from 1 to 100:");
                        str = Console.ReadLine();
                        if (int.TryParse(str, out value))
                            if (value >= 1 && value <= 100)
                            {
                                nums[i] = value;
                                i++;
                            }
                    }
                    int average;
                    int total = 0;
                    for (i = 0; i < Number; i++)
                        total = total + nums[i];
                    average = total / Number;
                    Console.WriteLine("average: " + average);
                    Console.WriteLine("total: " + total);
                }
                else
                    Number = 0;
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS