Oh, so you do have file reading problem. It is not "not working", it is working as intended and shows that there is file operation failure which you have missed completely.
The more I run it the more baffled I get.
I tweaked the text files. Gave myself 500 balls, and then used 100. I had sold a few pokemon I had to get the amount of 400200$ sold 27 pokemon to get 5400$ for them. Checked my stats and I went from 400200$ to 400 balls, 0 pokemon, 5400$ in my bag. Looking through the code now.
What exactly does it write? What compiler do you use?
Well, you did catch an exception. That means it got thrown. That means that there is problem with handling openng file and you did not do previous checks properly.
It can be that as Chervil said that your compiler does not like multiple opening of different files. Try to create own instance of ifstream for each file.
I removed the second loading. I'm using Dev-Cpp. Now, after removing the second load, it opens and wont create a random INT, but this time it is not going to load the files at all.
EDIT:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int a, b, c;
ifstream infile;
infile.open ("pokeballs.dat");
infile >> a;
x = a;
infile.close();
//
infile.open ("pokemons.dat");
infile >> b;
y = b;
infile.close();
//
infile.open ("cash.dat");
infile >> c;
z = c;
infile.close();
I edited back to the old one, and I'm getting random INT again, while with the code that MiiNiPaa gave, it is not going to load at all.
Which version of DevC++ ? It should be the Orwell version now at version 5.6.3 http://orwelldevcpp.blogspot.co.uk/
(version 4.9 was last updated in 2005 and is obsolete)
while with the code that MiiNiPaa gave, it is not going to load at all.
Of course. Because there is an error here. Which my code unearth and forces program termination.
Did you try that:
MiiNiPaa wrote:
It can be that as Chervil said that your compiler does not like multiple opening of different files. Try to create own instance of ifstream for each file.
Here is the code I came up with earlier. Basically you could change the case that runs the buy pokeballs to add the shop function to turn it into a shop.
143 C:\Dev-Cpp\Applications - Console\Numbers\main.cpp `selection' undeclared (first use this function)
143 C:\Dev-Cpp\Applications - Console\Numbers\main.cpp `SHOP' undeclared (first use this function)
177 C:\Dev-Cpp\Applications - Console\Numbers\main.cpp return-statement with a value, in function returning 'void'
143 error 'selection' undeclared means you have no selection variable defined.
143 error 'SHOP' undeclared again means you have no SHOP variable or such defined.
177 error means you are using a return statement in a void function.
Look at my code, I updated it to have an empty shop function and put comments in my switch statement where you would place it instead of purchasing 5 pokeballs.
My code is ugly, but I was trying to stay close to your code. I was attempting to simplify it by removing the extra calls and things you simply didn't need.
Bro, thanks but I don't want to get pre-made as I wont learn anything off it. It is better when I learn the things step by step. Also, I think you haven't got my point.
I want that from the shop() function, go to the again();, which is after the shop().
There, like MiiNiPaa code, but just that his code will give me errors..
Execute it. Let it return. Continue from where you been.