Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing the value found through '.contains'
    text
    copied!<p>This is a console unit conversion program which takes in a measurement unit (such as pounds, ounces) specified by the user, followed by a second measurement unit, and finally a value to convert from one unit to the other.</p> <pre><code>string userUnit1, userUnit2 = ""; int userValue = 0; </code></pre> <p>The units that can be used are specified in a text file, the contents of which are split into a string array (called 'units') in the program. The text file also contains the 'conversion value' between the two units. In the text file, they appear like so: ounce,gram,28.0 (since there's 28 grams in one ounce, this value is also put into the array).</p> <p>The units that the user enters are checked with the following snippet of code:</p> <pre><code>double result = 0; if (units.Contains(userUnit1) &amp;&amp; units.Contains(userUnit2)) { //??? Something like: //result = userValue */ value in the array element; } </code></pre> <p>The basic IF statement above checks the array for the units that the user enters, and what I want to do is use the conversion value in that array element to convert the number that the user entered. How would I go about this?</p> <p>EDIT: This is the code for storing the split text into the array.</p> <pre><code>using (read = new StreamReader("C:/Users/Sam Smith/Desktop/convert.txt")) { while (!read.EndOfStream) { lineFromFile = read.ReadLine(); lineFromFile.Split(' '); foreach (int i in lineFromFile) { count++; if (count % 3 == 0) { units.Add(lineFromFile); } } } } </code></pre>
 

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