The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 4 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
I had gotten help with a C# question the other day. I have another program that Im having issues with. I will attach the code I have so far.
C# Programming
A single class application that allows user to inout monthly rainfall amounts for one year storing the values in an array. Produce a report showing the month name along with the rainfall amount and its variance from the mean. Calculate the average rainfall for the year.Â
Here is some code that I was playing around with and attempting to alter. Ive gotten stuck every time I try to change the code.Â
......................................................CODE.............................................................
using System.IO;
using System;
Â
class Program
{
static void Main(string[] args)
{
string[] month = new string[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
double[] value = new double[12];
double varianceValue = 0.0;
Â
Console.WriteLine("*********************************************");
Console.WriteLine("THIS PROGRAM ALLOW YOU ENTER DATAr OF RAINFALLFOR ONE YEAR. A TABLEr DISPLAYED SHOWING THE MONTH WITHr RAINFALL FOR THAT MONTH AND VARIANCEr FROM THE MEAN. CALCULATE TOTALr RAINFALL FOR YEAR.");
Console.WriteLine("*********************************************");
Â
//The values are entered here.
for (int i = 0; i {
Console.Write("Enter the rainfall for {0}:",month[i]);
value[i] = Int32.Parse(Console.ReadLine());
}
Â
//Find the variance of a number
varianceValue = Math.Round(variance(value), 2);
Â
Console.WriteLine("*********************************************r");
//Output the calculated data
for (int i = 0; i {
Console.WriteLine("{0} = {1}",month[i], value[i]);
}
Console.WriteLine("Variance = {0}r", varianceValue);
Console.WriteLine("Total Annual Rainfall = {0}r", getSum(value) );
}
Â
//function to find the variance
static double variance(double[] nums)
{
if (nums.Length > 1)
{
// Get the average of the value
double avg = getAverage(nums);
double sumOfSquares = 0.0;
foreach (int num in nums)
{
sumOfSquares += Math.Pow((num - avg), 2.0);
}
return sumOfSquares / (double) (nums.Length - 1);
}
else { return 0.0; }
}
Â
// Get the average of our values in the array
static double getAverage(double[] nums)
{
int sum = 0;
if (nums.Length > 1)
{
foreach (int num in nums)
{
sum += num;
}
return sum / (double)nums.Length;
}
else
{
return (double)nums[0];
}
}
Â
//getting the sum of the values
static double getSum(double[] nums)
{
int sum = 0;
if (nums.Length > 1)
{
foreach (int num in nums)
{
sum += num;
}
return sum;
}
else
{
return (double)nums[0];
}
}
}
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly