When i saved some information, it all ended up into one variable.
Here is the code:
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <fstream.h>
char username[10];
int health;
int strength;
int xp = 0;
int main()
{
cout<<"Username>";
cin>>username;
ifstream input(username);
if (input)
{
cout<<"Sorry, username used.";
}
if (!input)
{
input.close();
int points = 10;
cout<<"You have 10 points- How much you want in strength?"<<endl;
cout<<"Strength= ";
cin>>strength;
if (strength > points)
{
cout<<"sorry. Impossible move!";
getch();
exit(0);
}
points = points - strength;
cout<<"You have "<<points<<" health.";
health = points;
ofstream output(username);
output<<health;
output<<strength;
output<<xp;
output.close();
}
getch();
return 0;
}
That makes the variables. Now to show them:
#include <iostream.h>
#include <conio.h>
#include <fstream.h>
char usrnm[10];
int xpmin;
int xpmax;
int lvl;
int strth;
int def;
int hlth;
int main()
{
cout<<"Username>";
cin>>usrnm;
ifstream input(usrnm);
if (!input)
{
cout<<"No such username";
}
else if (input)
{
input>>xpmin;
input>>xpmax;
input>>lvl;
input>>strth;
input>>hlth;
input>>def;
cout<<"level "<<lvl<<endl;
cout<<xpmin<<"/"<<xpmax<<" xp"<<endl;
cout<<def<<" defense \n";
cout<<strth<<" strength \n";
cout<<hlth<<" total health \n";
}
getch();
return 0;
}
I may have used stuff you guys dont usually use, but just tell me why instead of showing the diferant variables, it ends up the numbers are in hlth only. in other words:
when you enter like "def = 10" "strth=5" "hlth=5", then how come when you compile it it says:
level 0
0/0
0 defense
0 strength
155 health
that is what it is, maybe you can help maybe not, but please try