Witam. Mógłby ktoś wyjaśnić, jak pozbyć się tego błędu? Zarezerwowałem zmienną exp tylko raz, jeśli o to chodzi. Dla pewności sprawdziłem wszystkie wystąpienia frazy 'exp' w kodzie i wszystko jest w porządku. Co jest nie tak?
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <windows.h>
#include <conio.h>
#include <cmath>
#include <time.h>
using namespace std;
HANDLE c = GetStdHandle( STD_OUTPUT_HANDLE );
double dolar=100;
double cryptocurrency=0.00000458;
double cryptoToDolar=1287.42;
long long lvl=1;
int exp=0;
long long mana=200;
void loading();
void color(int n);
void menu();
void write();
void work();
void buysell(); void casino();
int main()
{
color(1); cout<<"Loading..."<<endl;
cout.setf(ios::fixed);
cout.precision(2);
srand(time(NULL));
loading();
system("cls");
menu();
}
void menu()
{
char letter;
write();
color(5);
cout<<"/---------------------------\\"<<endl;
cout<<"| MENU |"<<endl;
cout<<"| |"<<endl;
cout<<"| |"<<endl;
cout<<"| [A] Work to earn money |"<<endl;
cout<<"| [S] Buy / sell CRYPTOCOIN |"<<endl;
cout<<"| [D] Go to casino |"<<endl;
cout<<"| |"<<endl;
cout<<"| |"<<endl;
cout<<"\\---------------------------/"<<endl<<endl;
cout<<"Choose letter on keyboard"<<endl; /// Here user clicks on letter
letter = getch(); system("cls"); write();
if(letter=='a' || letter=='A') work();
else if(letter=='s' || letter=='S') buysell();
else if(letter=='d' || letter=='D') casino();
}
void write()
{
color(6); cout<<"Money: "<<dolar<<"$ and "<<setprecision(8)<<cryptocurrency<<setprecision(2)<<" in CRYPTOCOIN"<<endl;
cout<<"1 CRYPTOCOIN is "<<cryptoToDolar<<"$ for now"<<endl<<endl;
color(3); cout<<"|Lvl "<<lvl<<"|"<<endl<<"|";
for(int i=1; i<=20; i++) if(i<=exp) cout<<"X"; else cout<<"-";
cout<<"| "<<exp*5<<"% ["<<100-(exp*20)<<"% to Lvl "<<lvl+1<<"]"<<endl<<endl; /// How many % to next level
color(7); cout<<"MANA: "<<mana<<endl<<endl;
}
void color(int n)
{
if(n==1) SetConsoleTextAttribute(c, FOREGROUND_RED | FOREGROUND_INTENSITY); /// Red
if(n==2) SetConsoleTextAttribute(c, FOREGROUND_GREEN | FOREGROUND_INTENSITY); /// Green
if(n==3) SetConsoleTextAttribute(c, FOREGROUND_BLUE | FOREGROUND_INTENSITY); /// Blue
if(n==4) SetConsoleTextAttribute(c, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY); /// White
if(n==5) SetConsoleTextAttribute(c, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY); /// Cyan
if(n==6) SetConsoleTextAttribute(c, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY); /// Yellow
if(n==7) SetConsoleTextAttribute(c, FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY); /// Purple
}
void loading()
{
fstream file;
file.open("data.dat",ios::in);
if(file.good()==true) /// If file 'data.dat' exist and is available for this program
{
string line;
int lineNr=1;
while(getline(file,line))
{
switch(lineNr)
{
case 1: dolar = atof(line.c_str()); break;
case 2: cryptocurrency = atof(line.c_str()); break;
case 3: cryptoToDolar = atof(line.c_str()); break;
case 4: lvl = atoll(line.c_str()); break;
case 5: exp = atoi(line.c_str()); break;
case 6: mana = atoll(line.c_str()); break;
}
lineNr++;
}
}
file.close();
}
void work()
{
long long howmany;
color(5);
do
{
cin.clear(); cin.sync();
cout<<"How many operations you want to do (no more than 1000): ";
cin>>howmany;
} while(!cin || (howmany>1000 || howmany<1));
int arg1;
int arg2;
int chrr;
int result;
int userResult;
char sign;
for(int i=1; i<=howmany; i++)
{
system("cls"); write(); color(5);
arg1==rand()%400+100; /// Generate operation
arg2==rand()%400+100;
if(arg1%arg2!=0) chrr = rand()%3;
else chrr = rand()%4
if(chrr==0) {result = arg1 + arg2; sign='+';}
else if(chrr==1) {result = arg1 - arg2; sign='-';}
else if(chrr==2) {result = arg1 * arg2; sign='*';}
else if(chrr==3) {result = arg1 / arg2; sign='/';}
do
{
cout<<"Operation "<<i<<": "<<arg1<<" "<<sign<<" "<<arg2<<" = ";
cin>>userResult; cin.clear(); cin.sync();
} while(!cin);
}
}
void buysell()
{
}
void casino()
{
}