double x;
double b = 00.60;
double a =0.4; // ignore this double here!
cout << "Enter the ending time of the time scale! ex: 10.0" << endl;
cin >> x;
ofstream file1;
file1.open("timescale.txt");
for(double i = 0;i<x;){
file1 << i << endl;
if(i == b){ // here is the infamous if statement the problem lies in the
// i ==b part of if statement i dont get it why its never true!
cout << "mac donalds!" << endl; // i made some testing...
i = i+0.4;
b += 1;}
else i=i+00.01;} // this here works just fine
file1.close();
}
every time i run this the .txt just goes like this:
00.60, 00.61...
question 1 == why is this never true if(i == b)? by all logical sense to me it should be true at the moment i need it.
thank you!
thanks kbw it worked almoust perfectly
and i now have new problem
I inputted 10 and it printed in the .txt file 0.60, 1 and 1.60 ,2 but after that it started doing 2.60 , 2.61 ,3 until it reached 10
i only modified the code above this way
1 2 3 4 5 6 7 8 9 10 11 12 13
double b = 0.60;
double a =0.4;
rest of the code that is not important here.....
if(i > b){
cout << "mac donalds!" << endl;
i +=a;
b += 1;}
else i+=00.01;
}
You may have something like this instead: if( (i-b) < (0.01) )
So it will check their difference, and if it is less different than 0.01 (Depending on your i += 0.01; it will execute that statement.
If you change i += 0.01; also change if( (i-b) < (0.01) ).
thanks EssGeEich it worked better than my code above but if you change it to
if( (b-i) < (0.01))
for the first two numbers (0 and 1) it writes to the .txt 0.59,0.99, 1 ... 1.59, 1.99...
and then it starts working proberly 2.59,2.60,3...
i diden't change anything else than the if statement to
1 2 3 4 5 6 7 8 9 10 11 12 13 14
if( (i-b) < (0.01))
I ended fixing it like thisif((b-i) < (0.01)){
if(i < 2&&(b-i) < (0.01)){
i+=00.01;
file1 << i << endl;}
if(i < 2){
i +=a+00.01;}
else i +=a;
b += 1;}
else i+=00.01;
}
if there is easier way to fix that same problem please tell me but if not i think i will be just fine with that