Click here to Skip to main content
15,897,371 members

Comments by Member 13736730 (Top 5 by date)

Member 13736730 29-Nov-18 7:38am View    
thanks the code was correct just had put "=" by mistake.
Member 13736730 29-Nov-18 7:34am View    
thanks the code was correct just had put "=" by mistake.
Member 13736730 19-Nov-18 19:15pm View    
thanks for the reply, going witht the 2nd example it does need an iterator after the while loop to run 51 times doesnt it?
Member 13736730 1-May-18 14:42pm View    
The code was in c++ and I was converting it into c# and I’m not good at c# so some code have c++ characteristics
Member 13736730 20-Mar-18 9:45am View    
Deleted
using System;
using System.IO;

namespace ProfitCalculator
{
/// ==============================================================================

public class RangeFinder
{
/// <summary>
/// Performs calculations to find the start and end of the "best" data sequence
/// which has the greatest sum of data values over that sequence.
///
/// <param name="data">the data to be examined
/// <param name="bestStart">the start point found by the search
/// <param name="bestEnd">the end point found by the search
/// <param name="bestTotal">the sum of data values over that range
/// <param name="loops">the number of executions of the inner loop
public static void MaxSum1(double[] data, out int bestStart,
out int bestEnd, out double bestTotal, out int loops)
{
bestTotal = 0;
bestStart = 0;
bestEnd = 0;
loops = 0;
for
(int i = 0; i < data.Length; i++)
{
Console.WriteLine("Value {0}", data[i]);
}

}
public static void MaxSum2(double[] data, out int bestStart,
out int bestEnd, out double bestTotal, out int loops)
{
bestTotal = 0;
bestStart = 0;
bestEnd = 0;
loops = 0;
}
public static void MaxSum3(double[] data, out int bestStart,
out int bestEnd, out double bestTotal, out int loops)
{
bestTotal = 0;
bestStart = 0;
bestEnd = 0;
loops = 0;
}

/// ==============================================================================
/// <summary>
/// Tests the Profits Calculator
///
class Test
{
/// <summary>
/// The main entry point for the application.
///
static void Main()
{
double[] data;
int bestStart, bestEnd;
double bestTotal;
int loops;

/// name of the file and the number of readings
string filename = "week52.txt";
int items = 52;

data = new double[items]; /// create the data array

try
{
TextReader textIn = new StreamReader(filename);
for (int i = 0; i < items; i++) /// input and store the data values
{
string line = textIn.ReadLine();
data[i] = double.Parse(line);
}
textIn.Close();
}
catch
{
Console.WriteLine("File Read Failed");
return;
}

/// ---------------------------------------------------------------------
/// call the process method to find the best profit period
/// ---------------------------------------------------------------------

RangeFinder.MaxSum1(
data, out bestStart, out bestEnd, out bestTotal, out loops);

Console.WriteLine("Start : {0} End : {1} Total {2} Loops {3}",
bestStart, bestEnd, bestTotal, loops);

RangeFinder.MaxSum2(
data, out bestStart, out bestEnd, out bestTotal, out loops);

Console.WriteLine("Start : {0} End : {1} Total {2} Loops {3}",
bestStart, bestEnd, bestTotal, loops);

RangeFinder.MaxSum3(
data, out bestStart, out bestEnd, out bestTotal, out loops);

Console.WriteLine("Start : {0} End : {1} Total {2} Loops {3}",
bestStart, bestEnd, bestTotal, loops);