Reputation: 57
can input one by one by pressing enter but im trying to have it read one on line separated by spaces.
void readTestScores()
{
int i;
double tests;
Console.Write ("ENTER EXAM SCORE\t: ");
exam = Convert.ToInt32(Console.ReadLine());
Console.Write ("ENTER TEST SCORES\t: ");
for (i = 0; i < 7; i++)
{
tests = Convert.ToDouble (Console.ReadLine ());
testavg += tests;
}
testavg /= 7;
Console.WriteLine ("TEST AVERAGE IS\t\t: {0}",testavg);
}
Upvotes: 1
Views: 3307
Reputation: 149
Look into the string split method, as documented here:
https://msdn.microsoft.com/en-us/library/system.string.split%28v=vs.110%29.aspx
Usage would be to the effect of:
string s = Console.ReadLine();
double[] input = s.Split(' ').Select(t => Convert.ToDouble(t)).ToArray();
Upvotes: 3