Last active
December 29, 2015 12:39
-
-
Save d8ta/7671768 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
namespace bsp31 | |
{ | |
class MainClass | |
{ | |
static double[] data; | |
// main | |
static void Main (string[] args) | |
{ | |
Console.WriteLine("Summe: " + Summe()); | |
Console.WriteLine("Durchschnitt: " + Durchschnitt()); | |
Console.WriteLine("Maximum: " + Maximum()); | |
Console.WriteLine("Minimum: " + Minimum()); | |
Console.WriteLine("Standardabweichung: " + Standardabweichung()); | |
} // end of main | |
// function to read in usernumbers | |
static void readInNumbersCommandLine() | |
{ | |
Console.WriteLine("enter the length of your array: "); | |
double arraylength = checkInput(0, double.MaxValue); | |
double[] data = new double[arraylength]; | |
////filling the array with user input | |
for (int i = 0; i < data.Length; i++) | |
{ | |
Console.Write("enter a number you wish to hold in your array: "); | |
data[i] = checkInput(0, double.MaxValue); | |
} | |
//printing out the array | |
Console.WriteLine("here is your array: "); | |
for (int i = 0; i < data.Length; i++) | |
{ | |
Console.WriteLine(data[i]); | |
} | |
} // end of function | |
// check user input for negative numbers or strings | |
static double checkInput (double min, double max) | |
{ | |
bool inputIsOK; | |
double userInput; | |
do { | |
inputIsOK = double.TryParse (Console.ReadLine (), out userInput); | |
if ((inputIsOK == true) && (userInput >= min) && (userInput <= max)) { | |
inputIsOK = true; | |
} else { | |
inputIsOK = false; | |
Console.WriteLine ("try again, your input is wrong!"); | |
} | |
} while (inputIsOK == false); | |
return userInput; | |
} // end of function | |
// function for the sum | |
static double Summe() | |
{ | |
double sum = 0; | |
for (int i = 0; i < data.Length; i++) | |
{ | |
sum += data[i]; | |
} | |
return sum; | |
} // end of function | |
// function for average | |
static double Durchschnitt () | |
{ | |
double average = Summe() / data.Length; | |
return average; | |
} // end of function | |
// function for max | |
static double Maximum() | |
{ | |
double max = data.Max(); | |
return max; | |
} // end of function | |
// function for min | |
static double Minimum() | |
{ | |
double min = data.Min(); | |
return min; | |
} // end of function | |
// function for standard deviation | |
static double Standardabweichung() | |
{ | |
double average = Durchschnitt(); | |
double sumOfSquares = data.Select(val => (val - average) * (val - average)).Sum(); | |
double sd = Math.Sqrt(sumOfSquares / data.Length); | |
return sd; | |
} // end of function | |
} | |
} | |
Ok, für die for loops i als int setzten hilft schonmal... einen fehler gibt es noch in zeile 28
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem ist, er möchte das nicht als double eingabe haben und sagt: "cannot convert 'double' to 'int'... hab aber keinen int mehr drinne.....