Can't get MTG program too work?

I'm trying to make a program that let's you play magic the gathering through console, but I an't get the while loop to work. It only runs twice. Here is the code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <string>
#include <fstream>


using namespace std;


int main()
{
cout << "Enter your deck's cards and their stats one by one." << endl;
ofstream inputFile("C:/users/youtube area/desktop/MTG.txt");
ifstream inputfile2("C:/users/youtube area/desktop/MTG.txt");
string input;
cin >> input;
string thing;
inputfile2  >> input;
int numofcards;
++numofcards;
while (thing == "y")
{
    cout << "Enter your next card" << endl;
    cin >> input;
    inputfile2 >> input;
    cout << "Would you like to continue? (y/n)" << endl;
    cin >> thing;
    ++numofcards;
    cout << "Card count:" << endl << numofcards << endl;
}
}
thing is an empty string initially, so the while loop will never be entered.
Also, you're reading a word from cin into input, but you're overwriting it each time before actually using it.
In line 19, you're using numofcards uninitialized.

Why are you opening the same file twice? If you want to be able to both read and write, you should use an fstream.
I want it so it writes in the file what I enter the first time, then, when I overwrite the string, it writes what I enter on ANOTHER line. Oh, and I changed it so thing = y after I posted this, but now it runs the loop jiust twice
Topic archived. No new replies allowed.