Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get my program to output all values of the array Numbers to a file
    primarykey
    data
    text
    <p>I am trying to create a lottery program within c++ and the issue i'm having is attempting to output all values of the Numbers array into a file, however when i run the code, the only thing that gets outputted is the first set of values i put in, however the program allows me to type in more than one set. (The program allows for up to 6 sets of data), however it only outputs one. Here is all my code</p> <p>LotteryData.cpp</p> <pre><code>LotteryData::LotteryData() { } LotteryData::~LotteryData() { } void LotteryData::PassInfo(int (&amp;Numbers)[6][6], int &amp;NumberofGames) { ofstream Numfile; while(NumberofGames&gt;0) { Numfile.open("Numbers.txt"); for (int j=0; j&lt;6; j++) { Numfile &lt;&lt; Numbers[NumberofGames][j]; } NumberofGames = NumberofGames - 1; Numfile.close(); } } </code></pre> <p>Player.h</p> <pre><code>#pragma once #include &lt;iostream&gt; #include &lt;fstream&gt; using namespace std; class Player { private: public: Player(); ~Player(); void Input(); int Numbers[6][6]; int NumberofGames; }; </code></pre> <p>main.cpp</p> <pre><code>#include &lt;iostream&gt; #include "Lottery.h" #include "Player.h" #include "LotteryData.h" using namespace std; int main() { Player player; Lottery random; LotteryData data; player.Input(); random.setRandomNumber(); data.PassInfo(player.Numbers, player.NumberofGames); } </code></pre> <p>Im not exactly sure where the problem is coming from but i think it may be from one of the pointers although not entirely sure. Any help on this problem would be much appreciated. Cheers</p> <p>Edit: I've Changed the code within the PassInfo function within LotteryData.cpp file as @ali suggested Edit2: I've cut down on the code as to where I think the problem occurs but as all of the code compiles, Visual Studio 2012 doesnt point to any actual errors in the program</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