Note that there are some explanatory texts on larger screens.

plurals
  1. POArrays and measurement unit conversion
    primarykey
    data
    text
    <pre><code>using (read = new StreamReader("C:/Users/Sam Smith/Desktop/convert.txt")) { while (!read.EndOfStream) { lineFromFile = read.ReadLine(); units = lineFromFile.Split(','); if (units.Contains(splitEntry[0]) &amp;&amp; units.Contains(splitEntry[1])) { firstUnit = units[0]; secondUnit = units[1]; userConvertValue = Convert.ToDouble(splitEntry[2]); fileConvertValue = Convert.ToDouble(units[2]); result = fileConvertValue * userConvertValue; } if (units.Contains(splitEntry[0]) &amp;&amp; units.Contains(splitEntry[1])) { firstUnit = units[1]; secondUnit = units[0]; userConvertValue = Convert.ToDouble(splitEntry[2]); fileConvertValue = Convert.ToDouble(units[2]); result = userConvertValue / fileConvertValue; } if (!units.Contains(splitEntry[0]) || !units.Contains(splitEntry[1])) { Console.WriteLine("Error, measurement unit not recognised."); } </code></pre> <p>Above I have a text file that contains types of unit measurement (pounds, ounces, miles and such), the text from this file is split into a string array. The user enters two measurement units in the following format to convert to two units: unit,unit,amount In the text file, the conversion amount for two units is every third split string, like so: unit,unit,2.80 unit,unit,1.27 (etc)</p> <p>Is there a way of grouping each set of units and their conversion amounts? For example, if the user tries to convert two particular units, the program knows which conversion value to use when calculating the final result. Might be a little vague, but it's difficult to explain. EDIT: The user does not interact with the file, the program simply pulls the data from the file, which is then split into strings (',') and stored in an array.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload