title: c++ Printing from a struct
body: <p>I'm working on something and the gist of what I have to do is essentially:</p>
  
  <p>1) Declare a struct named partType that has two members: name (holds the name of a
  part) and code (holds a whole number).</p>
  
  <p>2) Declare two variables of type partType.</p>
  
  <p>3) Prompt the user to enter the name and code of the first item and store them
  into the corresponding variable.</p>
  
  <p>4) Prompt the user to enter the name and code of the second item and store them
  into the corresponding variable.</p>
  
  <p>5) Compare the items by code and display an output like the one shown in the
  examples below:</p>
  
  <p>Example 1:
  Enter name and code of item1: bolt 22222</p>
  
  <p>Enter name and code of item2: nut 11111</p>
  
  <p>bolt goes after nut in the inventory</p>
  
  <p>Example 2:
  Enter name and code of item1: bolt 11111</p>
  
  <p>Enter name and code of item2: nut 22222</p>
  
  <p>bolt goes before nut in the inventory</p>
  
  <p>The current code that I have is: </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  struct partType {
      string name;
      int code;
  };
  
  int main() {
  
      partType nam, num;
  
      cout &lt;&lt; "enter name and code of item1: ";
      cin &gt;&gt; nam.name &gt;&gt; num.code;
      cout &lt;&lt; "enter name and code for item2: ";
      cin &gt;&gt; nam.name &gt;&gt; num.code;
  
      if (num.code &gt; num.code) {
          cout &lt;&lt; nam.name &lt;&lt; " goes after " &lt;&lt; nam.name;
      }
      else if (num.code &lt; num.code) {
          cout &lt;&lt; nam.name &lt;&lt; " goes before " &lt;&lt; nam.name;
      }
      else {
          cout &lt;&lt; "tie";
      }
  
      system("pause");
      return 0;
  }
  </code></pre>
  
  <p>I feel that I shouldn't be using the nam and num twice because it'll overwrite it but I'm not completely sure on how to fix it</p>